现在由于某种原因我无法让这段代码工作 当我将鼠标移到
jQuery 代码:
$(function() {
var id = this.id;
$("tr").hover(function() {
$("#remove_" + id).show();
}, function() {
$("#remove_" + id).hide();
});
});
PHP 代码:
$result = mysql_query("SELECT * FROM wall WHERE uid='$myid' ORDER BY id DESC") or die (mysql_error());
while ($row = mysql_fetch_array($result)) {
$id = $row['id'];
$uid = $row['uid'];
$fid = $row['fid'];
$action = $row['action'];
echo "< table width='467' border='0' align='left' cellpadding='0' cellspacing='0'>
< tr id='wall_$id'>
< td width='18' height='25'> < /td>
< td width='396' valign='top' class='txt'>RickStar has upload new photos. - < span class='comment'>
< a href='#'>Comment< /a>< /span>< br />< /td>
< td width='53' valign='top'>< span class='txt'>
< div id='remove_$id' class='mydiv'>Remove< /div>
< /span>< /td>
< /tr>
< /table>";
}
最佳答案
将您的 jQuery 代码更改为:
$(function() {
$("tr").hover(function() {
var id = this.id.split('_').pop();
$("#remove_" + id).show();
}, function() {
var id = this.id.split('_').pop();
$("#remove_" + id).hide();
});
});
应该可以了。 Here's a working example if you need more help .
您的代码无法正常工作有两个原因:
- 过早设置 ID,在悬停功能之外
this
未定义或不是您的想法。 - 你需要拆分
<tr>
的 ID_
获取实际 ID,然后使用它获取<div>
.
关于Php jquery 鼠标悬停帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/989481/