8

如何在 jQuery 中获取所有 'colspan' 大于 1 的 td 元素?

var nodes = $('td[colspan>1]');

上面的代码似乎不起作用。

4

3 回答 3

10

由于没有 colspan=0 你可以做

$('td[colspan]').not('[colspan=1]')
于 2012-06-19T07:21:55.827 回答
7

使用过滤器

var nodes = $('td[colspan]').filter(function() {
  return +$(this).attr('colspan') > 1
});

+前面的 to将$(this).attr('colspan')字符串转换为数字

于 2012-06-19T07:17:28.667 回答
2
var tds = $('td')​​​.each(function(){
    if($(this).attr('colspan') > 1){
        return  $(this);
    }
})​
于 2012-06-19T07:21:49.290 回答