Php jquery 鼠标悬停帮助

标签 php javascript jquery mysql

现在由于某种原因我无法让这段代码工作 当我将鼠标移到 上时,我希望 #remove_$id 显示,然后在鼠标移开时隐藏

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'>&nbsp;< /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/

相关文章:

javascript - css api 的 jquery if else 条件

javascript - 设置对象名称?

php - MP3 播放器,如grooveshark

php - 未找到包含内部 namespace

php - 在 PHP 中,为什么 json_encode 比序列化慢?

javascript - 在 Angular 指令中访问 $error

jquery - IE8 和 jQuery 空指针

javascript - 考虑到分钟,如何检查当前时间是否在特定范围内

javascript - 为什么 jQuery 提交这个表单?

php - file_get_contents 的相对 PHP 路径