父元素的事件幫助我弄清楚如何父元素(<tr>
) 我找不到錯誤在條件上設置事件如何設置使用jQuery
<script type="text/javascript">
$('table tbody tr').each(function(){
$(this).find('a:first').click(function(){
if($(this).parents().get(1).tagName == 'TR') {
$(this).parents().get(1).find('tr').css('background', 'red'); //What's wrong?
}
});
</script>
<table>
<tbody>
<tr>
<td><a href="#">text</a></td>
<td>text</td>
</tr>
</tbody>
</table>
不幸的是,格式化,我看不出有什麼更特殊的標記
如果你使用'console.log'或'alert($(this).parents()。get(1))'',你會得到什麼? – 2010-09-28 07:31:40