jquery使用sql脚本创建新div
嗯,我正在制作一个工具提示脚本,它正在工作,但我意识到一旦我有很多工具提示,我的网页就会变慢,所以我尝试更改脚本,只创建需要的内容 这个JS找到一个“itemtooltip”类(它是一个img),然后调用脚本来创建工具提示jquery使用sql脚本创建新div,jquery,sql,ajax,tooltip,Jquery,Sql,Ajax,Tooltip,嗯,我正在制作一个工具提示脚本,它正在工作,但我意识到一旦我有很多工具提示,我的网页就会变慢,所以我尝试更改脚本,只创建需要的内容 这个JS找到一个“itemtooltip”类(它是一个img),然后调用脚本来创建工具提示 jQuery('.itemtooltip').hover(function(){ var datas = jQuery(this).data('tip'); var dataString = "value="+datas; jQuery.ajax({
jQuery('.itemtooltip').hover(function(){
var datas = jQuery(this).data('tip');
var dataString = "value="+datas;
jQuery.ajax({
type: "POST",
url: "http://www.dawnsource.com/work/scripts/createitemtooltip.php",
data: dataString ,
success: function(msg) {
jQuery('#bg-overlay').html(msg);
}
});
var offset = jQuery(this).offset();
console.log(offset)
var width = jQuery(this).outerWidth();
jQuery('#tooltip-container' + jQuery(this).data('tip')).css({top:offset.top, left:offset.left + width + 10}).show();
}, function(){
jQuery('#tooltip-container' + jQuery(this).data('tip')).hide();
});
脚本:
<?
$aux = $_POST['value'];
$query2 = "SELECT u.Id_item, u.name, u.effect, u.passive, u.image, u.cost FROM items AS u WHERE u.name = $aux";
$resultado2= mysqli_query($con,$query2);
$l = mysqli_fetch_assoc($resultado2);
$string = str_replace(' ', '', $l['name']);
$string2 = $l['passive'];
if ($string2 == 'null') $string2 = ' ';
$name = $l['name'];
$cost = $l['cost'];
$effect = $l['effect'];
echo '<div class="tooltip-container" id="tooltip-container$string">
<div style="width:300px; margin:3px;">
<div class="title" style="width:200px; float:left;">$name</div>
<div class="text" style="float:left;">Cost:</div><div style="color:#FC0; float:left; font-size:12px;"> $cost<img src="http://www.dawnsource.com/work/images/random/vim2.png" width="15" height="15"></div>
<div class="effects" style="width:250px; float:left;">$effect</div>
<? if ($string2 != " " ){ ?>
<div style="width:280px; font-weight:bold; float:left; font-size:12px;">
Passive:<div class="text" style="float:left;">$string2</div>
</div>
<? } ?>
</div>
</div>';
?>
问题在于回音没有输出变量,而是创建了如下内容:
<div class="tooltip-container" id="tooltip-container$string">
等等
我试过使用echo'text'+变量+'text';但不以这种方式输出任何内容
提前感谢。试试:
<div class="tooltip-container" id="tooltip-container'.$string.'">
“text”+variable+“text”是将变量连接到string out put的JS方式。一般来说,在PHP中,您希望通过使用“..”打破封装,在您的例子中,使用中间的变量。这不是对您的问题的回答,而是您可以考虑的一点:与其向PHP部分请求HTML字符串,不如只加载JSON数据并在JS中使用它。还有一个好处:在HTML中编写一次工具提示所需的DOM,用JS修改内容,设置绝对位置,然后。。。不再需要DOM注入。我想快多了。只是我的想法。第二种方法听起来不错,我怎么能做到呢?让ajax查询信息,然后如何更改工具提示的内容?