這裏的是我的jquery:動態加載PHP,.load()時,不使用jQuery已經頁面
$(function(){
$('.messagediv').on('mouseover', function() {
$(this).find('.deletelistenchatcontainer').css({'display':'block'});
$(this).find('.hidefordeletelistenchat').css({'display':'none'});
}).on('mouseout', function(){
$(this).find('.deletelistenchatcontainer').css('display', 'none');
$(this).find('.hidefordeletelistenchat').css({'display':'block'});
});
});
這裏是我的PHP:
$id2 = mysql_real_escape_string($id2);
$getdata8 = mysql_query("SELECT * FROM musicbook WHERE identify='$identify' ORDER BY id DESC LIMIT 20");
$numrowsgetdata = mysql_num_rows($getdata8);
if ((mysql_num_rows($getdata8))<1)
{
echo "<i>Be the first to say something?</i><p/>";
}
while ($row8 = mysql_fetch_assoc($getdata8))
{
$id8 = $row8['id'];
$name8 = $row8['name'];
$message8 = $row8['message'];
$message10 = nl2br($message8);
$date8 = $row8['date'];
if ($name8==$username)
{
echo "
<section class='hover'>
<div class='messagediv' style='background:#1A1A1A;'><div style='padding:5px;'>$message10<br/>
<div style='margin-top:4px; font-size:.8em; float:left;'><div class='hidefordeletelistenchat' style='float:left;'><a href='http://www.pearlsquirrel.com/$name8' style='color:white;'>$name8</a><font style='color:#D6D6D6'> on $date8</font></div>
<div class='deletelistenchatcontainer' style='float:left;color:#FFF;display:none;z-index:10;background:#1a1a1a'><input type='hidden' id='wpm2' value='$id8'><img src='cross.png' style='float:left;' alt='PearlSquirrel'/><span class='hoverdeletetext' onclick='LinkOnClick4($id8);'>Delete</span></div></div></div></div>
</section>
";
}
else
{
echo "
<div class='messagediv'><div style='padding:5px;'>$message10<br/>
<div style='margin-top:4px; font-size:.8em; float:left;'><div style='float:left;'><a href='http://www.pearlsquirrel.com/$name8' style='color:white;'>$name8</a><font style='color:#D6D6D6'> on $date8</font></div>
</div></div></div>";
}
}
if($numrowsgetdata >= 20)
{
echo "<div id='loadingcomments'><img src='loading.gif' style='height:30px; width:30px;'></div>";
}
上面的代碼工作正常。但是,這是一個用戶評論系統。在用戶刪除評論後,我重新加載了一個具有上述php功能的div,但是當我這樣做時,我上面的jquery不再適用於動態生成的內容。我知道這是用加載的.load()屬性加載的內容的一個問題,我正在使用它,但有人知道如何使其正常工作?我需要使用.live()屬性還是其他的?謝謝!
所以它會是$(this).get('。deletelistenchatcontainer')。css({'display':'block'});? – Eggo 2012-04-07 23:52:04
因爲這似乎並不奏效。 – Eggo 2012-04-07 23:53:13