2011-03-11 76 views
0

我有以下腳本----Jquery代碼不工作!

$("tr.member_profile_comment_row_frame").mouseover(function() { 
    $(this.element."img.member_profile_comment_show_delete_button").show(); 
    }); 
    $("tr.member_profile_comment_row_frame").mouseout(function() { 
    $(this.element."img.member_profile_comment_show_delete_button").hide(); 
    }); 

我想的事情是,該錶行具有類member_profile_comment_show_delete_button規定中有一個元素應該顯示和隱藏鼠標懸停及移出錶行!但是有很多像這樣的表格行!而且我無法找到一種方式只顯示鼠標指向的表格行中的img!

請幫我一把!

在此先感謝!

+0

你能在這裏顯示你的完整頁面標記嗎? – 2011-03-11 09:13:09

回答

1

你的代碼中不需要this.element,只是選擇器;之後的this意味着看這個元素。

$("tr.member_profile_comment_row_frame").mouseover(function() { 
    $("img.member_profile_comment_show_delete_button", this).show(); 
}); 
$("tr.member_profile_comment_row_frame").mouseout(function() { 
    $("img.member_profile_comment_show_delete_button", this).hide(); 
}); 
+0

感謝它的工作!!!!! – 2011-03-11 09:26:35

0

您應該在這裏使用.delegate()help。看起來像:

$('table').delegate('tr', 'mouseenter', function(e) { 
    $(this).find('img.member_profile_comment_show_delete_button').show(); 
}).delegate('tr', 'mouseleave', function(e) { 
    $(this).find('img.member_profile_comment_show_delete_button').hide(); 
}); 

這有個好處,只有一個事件處理程序必將爲您的所有<tr>節點(您<table>節點)。

您的當前代碼也可以正常工作(除此之外this.element需要替換爲this),但它會明確地將事件處理程序綁定到每個<tr>

+0

感謝它的工作! – 2011-03-11 09:27:15