我使用多个文本框让用户输入不同的信用cards#,并进行jquery验证。模棱两可的是,只有第一个文本框验证有效。验证对其他框不起作用。error console中也没有js错误。
如果有人能给我点提示,那就太好了。
//for first textbox
$("#cust_reg").validate({
rules: {
cc_num_local: {
required: true,
creditcard: true
}
}
});
//for second textbox
$("#cust_reg").validate({
rules: {
cc_num_roam: {
required: true,
creditcard: true
}
}
});仅相关的html:http://pastie.textmate.org/2422338
发布于 2011-08-24 21:51:54
您可以使用cust_reg的id拥有多个HTML元素。如果你这样做了,那么你的JavaScript代码将只有一个可用,因为其中一个会取代另一个。它也不是有效的HTML。您需要将第二个字段的名称更改为不同的名称,如cust_reg2。
发布于 2015-04-08 09:02:40
因为您有一个表单和两个不同的ID,所以您可以尝试在代码中组合它们。
$("#cust_reg").validate({
rules: {
cc_num_local: {
required: true,
creditcard: true
},
cc_num_roam: {
required: true,
creditcard: true //Not sure if this can be the same name
}
}
});https://stackoverflow.com/questions/7176485
复制相似问题