Javascript 带有嵌套数组的jQuery验证插件出现意外结果
我正在使用以下jQuery验证插件: 我正在尝试验证另一个数组中的嵌套数组“tax_percents[]”。它只验证数组中的第一个值。奇数部分是,对于数组中的第二个字段,它会验证它,并在字段1中给出错误消息 以下是显示错误的实时演示: 我有以下文件:Javascript 带有嵌套数组的jQuery验证插件出现意外结果,javascript,jquery,arrays,validation,Javascript,Jquery,Arrays,Validation,我正在使用以下jQuery验证插件: 我正在尝试验证另一个数组中的嵌套数组“tax_percents[]”。它只验证数组中的第一个值。奇数部分是,对于数组中的第二个字段,它会验证它,并在字段1中给出错误消息 以下是显示错误的实时演示: 我有以下文件: <!DOCTYPE html> <html> <head> <script src="jquery.min.js"></script> <script src="jquery.v
<!DOCTYPE html>
<html>
<head>
<script src="jquery.min.js"></script>
<script src="jquery.validate.js"></script>
</head>
<body>
<form action="" method="post" id="theForm">
Location 1 Tax 1:
<input type="text" name="locations[1][tax_percents][]" />
<br /><br />
Location 1 Tax 1:
<input type="text" name="locations[1][tax_percents][]" />
<br /><br />
Location 2 Tax 2:
<input type="text" name="locations[2][tax_percents][]" />
<br /><br />
Location 2 Tax 2:
<input type="text" name="locations[2][tax_percents][]" />
<input type="submit" />
</form>
<script>
$("#theForm").validate({
rules:
{
"locations[1][tax_percents][]":
{
number: true
},
"locations[2][tax_percents][]":
{
number: true
}
}
});
</script>
</body>
</html>
地点1税务1:
地点1税务1:
地点2税务2:
地点2税务2:
$(“#表格”)。验证({
规则:
{
“地点[1][tax_percents][]”:
{
数字:对
},
“地点[2][tax_percents][]”:
{
数字:对
}
}
});
我做错了什么?库不支持将事物命名为相同名称并验证每个输入的功能。您说:“奇怪的部分是,对于数组中的第二个字段,它会验证它并在字段1中给出错误消息。”我看到两个输入以相同的名称重复。这可能是一个原因…也许,这个答案会帮你多一点。我知道我被允许使用相同名称的输入。(这正是我在服务器端所需要的,但它使客户端验证变得棘手)