請考慮下面的jQuery驗證代碼的簡單形式。不知怎的,我仍然(不)與規則的語法出錯,因爲驗證不以這種方式工作(當我檢查了一些關於此主題的stackoverflow上的網站)。如何正確使用數組描述規則?jQuery數組驗證不起作用
請幫助。
代碼:
<form id="myForm" name="myForm" action="" method="post" autocomplete="on">
<label class="field2" for="productname[0]"> Product name 1 </label> <input id="productname[0]" type="text" name="productname[0]"> <br>
<label class="field2" for="productname[1]"> Product name 2 </label> <input id="productname[1]" type="text" name="productname[1]"> <br>
<input type="submit" name="submitForm" value="Submit Form">
<script src="js/jquery-1.10.1.min.js"></script>
<script src="js/jquery.validate.js"></script>
<script>
$(function() {
$("#myForm").validate({
rules: {
'productname[]': {
required:true,
minlength: 2,
maxlength: 30,
}
} //rules
}); //validate()
}); //function
</script>
</body>
thnx,這是可行的(!) – Joppo