$(document).ready(function(){
$("#box-table-a").each(function(){
var temp2=$(this).find(".tool-id").html();
$("#box-table-a span").qtip({
content: {
url: 'description-hover.php',
data: { id: temp2 },
method: 'post'
},
show: 'mouseover',
hide: 'click'
});
});
});
<table id="box-table-a" class="tablesorter">
<thead>
<tr>
<th scope="col" style="cursor:pointer;">B-House/Dorm Name</th>
<th scope="col" style="cursor:pointer;">Address</th>
<th scope="col" style="cursor:pointer;">Price Range</th>
<th scope="col" style="cursor:pointer;">Date Added</th>
<th scope="col" style="cursor:pointer;">Status</th>
</tr>
</thead>
<tbody>
<?php
$q=mysql_query("select * from property");
while( $f=mysql_fetch_array($q, MYSQL_ASSOC))
{
$p_id=$f["p_id"];
echo"
<tr>
<td id='tool-table'><span class='tool-id'>".$p_id."</span>
<span id='testid' style='cursor:pointer'>".$f['p_name']."</span></td>
<td id='pretty'>".$f['address']."</td>
<td>".$f['p_name']."</td>
<td>".$f['payment_type']."</td>
<td>".$status."</td>
</tr>
";
}
?>
</tbody>
</table>
temp2变量假设得到span的每个值(p_id),所以当我悬停时我可以在工具提示中显示描述。但显示总是一样的。我的代码怎么了?
答案 0 :(得分:1)
你可以这样做:
$(".tool-id").each(function(){
var temp2=$(this).html();
$(this).siblings("span").qtip({ // whatever span you want to set - change here
content: {
url: 'description-hover.php',
data: { id: temp2 },
method: 'post'
},
show: 'mouseover',
hide: 'click'
});
});
// Added for follow up request :)
$(document).click(function()
{
if($('#testid').is(':visible){
$(this).hide();
}
});
答案 1 :(得分:0)
将$(“#box-table-a”))更改为$(“#box-table-a tr”))