我有一个JSFiddle:http : //jsfiddle.net/dPAAG/
我可以遍历已选中复选框的行...
$('#ordertable').find('input[type="checkbox"]:checked').each(function () {
//this is the current checkbox
var row = $(this);
// this is null
var stuff = row.find('.productVal').val();
alert('this is a checked checkbox');
});
但是我似乎无法获得同一行中第一个文本框的值。我正在尝试通过使用类名来访问它,但是它似乎不起作用。该变量始终是未定义的。
我是否缺少简单的东西?
row
是对不能包含后代元素的输入的引用。您缺少closest
选择tr
输入的最接近父级的方法:
var row = $(this).closest('tr');
您还可以使用过滤has
方法:
$('#ordertable tr').has('input[type="checkbox"]:checked').each(function () {
// `this` here refers the matching `tr` element
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句