2009-06-12 21 views
1

由於某種原因,我無法使此代碼正常工作 當我將鼠標移過<時,我想讓#remove_ $ id顯示然後隱藏當鼠標移離Php jquery鼠標過度幫助

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>"; 


} 

回答

2

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>
0

你把鼠標放在td上,而不是tr。

+0

? ...... TR支持:懸停在JS中的css和mouseover/mouseout中。 – 2009-06-12 23:44:18