我正在尝试在表格标题上获取点击事件,这使用 jQuery 很容易。 我希望点击事件在除第一个标题之外的所有标题上都处于事件状态。
我正在使用 CSS 的 :nth-child() 属性转义第一个 header 。
我就是这样做的
$(function(){
$('th:nth-child(2 3 4 5)').click(function(){
$(this).CSS("font-weight","bolder");
});
});
我没有得到结果。我可以用 :nth-child()
本身来做更好的方法吗?
最佳答案
你可以使用:not
。
$('th:not(:first-child)').click(function(){
或
你可以使用:gt(0)
$('th:gt(0)').click(function(){
评论回复
对于奇数选择器,您可以使用 :odd jQuery
选择器。
Official Document
示例
$('th:not(:odd)').click(function(){
关于jquery - :nth-child() selector, 多个第 n 个 child ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15963267/