我希望更改此代码,因为 nth-child(3)
不适用于 IE8。如何将代码的这一部分和其他部分更改为 jquery 中的 jquery.each
?
var allValues = $('#myTable td:nth-child(3) input').map(function() {
return $(this).val();
}).toArray();
最佳答案
您可能不需要使用.each()
;您可以使用过滤器来执行nth-child
的工作,如下所示:
var allValues = $('#myTable td').filter(function() {
return $(this).closest('tr').children('td').index( this ) === 2;
})
.find('input').map(function() {
return $(this).val();
}).toArray();
请记住 jQuery 2.x supports IE > 8.
var inputs = $('#myTable td:nth-child(3) input').filter(function() { return $(this).val() == value; });
将是:
var inputs = $('#myTable td').filter(function() {
return $(this).closest('tr').children('td').index( this ) === 2;
})
.find('input').filter(function() { return $(this).val() == value; });
关于javascript - 使用 jqueryeach 循环而不是 td : nth child(3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26965137/