我正在尝试使用 jQuery each() 遍历一组名为 supplier_type[] 的复选框。它们都有唯一的 id,所以我可以重写它来处理一组唯一的 id,但我想弄清楚我在哪里出错了。
警报显示,虽然 intIndex 看到正确数量的元素this
始终包含第一个元素。
function setUp(){
$( 'input[name=supplier_type[]]' ).each(
function( intIndex ){
var type = $(this+':checked').val() + 'Table';
$("#"+type).show("slow");
alert($(this+':checked').val()); // sees first one each iter
}
);
}
那么我该如何处理正确的元素呢?我需要使用绑定()吗?
谢谢!
// 根据 Drew Wills 的响应编辑工作版本。谢谢德鲁!
function setUp(){
$( 'input[name=supplier_type[]]' ).each(
function( intIndex ){
if($(this).attr('checked')) {
var type = $(this).val() + 'Table';
$("#"+type).show("slow");
}
}
);
}