2012-01-13 18 views
5

如何排除我在下面創建的jquery的單擊事件上的第一個td?我想排除生成對話框的單擊事件中所有行的第一個td。jquery排除第一個點擊事件td?

jQuery("#list tbody tr").click(function(){ 

//some code here 

}); 

<table> 
    <tr> 
     <td>first</td> 
     <td></td> 
     <td></td> 
    </tr> 
    <tr> 
     <td>first</td> 
     <td></td> 
     <td></td> 
    </tr> 
</table> 

回答

13

如何使用first-child選擇與:not組合:

jQuery("#list tbody tr td:not(:first-child)").click(function(){ 
    //some code here 
}); 

實施例:http://jsfiddle.net/Rq8Xf/

+0

有錯誤...我的數據取決於我的整個表格行。 here http://intelaface.com/demo/lpc/products – kedomonzter 2012-01-13 06:32:02

+0

@mocca:我不確定你的意思 - 你能提供更多的細節嗎? – 2012-01-13 13:59:40

0
jQuery("#list tbody td").not(':first').click(function(){ 

    //some code here 

}); 
1
jQuery("#list tbody tr td:not(:first)") 
1
$('#list tr td:not(:first)').click(function() { 
    // ... 
}) 

順便說一句。你從哪裏得到tbody?另外,你的表需要一個id = 「名單」,所以:

<table id="list"> 
    <tr> 
     <td>first</td> 
     <td></td> 
     <td></td> 
    </tr> 
    <tr> 
     <td>first</td> 
     <td></td> 
     <td></td> 
    </tr> 
</table> 
2

試試這個,

jQuery("#list tbody tr").each(function() { 
    jQuery("td:not(:first)",this).click(function() { 
     alert($(this).text()); 
     //some code here 
    }); 
}); 

記住你是在HTML中使用TBODY以及