javascript - 使用 jqueryeach 循环而不是 td : nth child(3)

标签 javascript jquery internet-explorer

我希望更改此代码,因为 nth-child(3) 不适用于 IE8。如何将代码的这一部分和其他部分更改为 jquery 中的 jquery.each

var allValues = $('#myTable td:nth-child(3) input').map(function() {
    return $(this).val();
}).toArray();

see FIDDLE DEMO

最佳答案

您可能不需要使用.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/

相关文章:

javascript - 基于文本的rpg javascript练习项目

javascript - 如何选择列表的每个 next() 元素并取消选择 prev()?

javascript - 如何在 javascript 中获取 x=undefined

php - 数组通过ajax传递但在php中作为字符串接收

javascript - "Interner Explore has stop working"在 IE 11 中出现问题当用户在 html 数字输入上进行选项卡时

css - 最小高度不能正常工作?

javascript - AngularJS Smart Table 在显示所有行时用空格过滤特殊字符

javascript - Moment.js 周数的日期不正确

javascript - NodeJs 中的变量值是否可以为 "save"?

javascript - node.appendChild 在 <= IE9 中的行为不符合预期(尚未检查 10)