使用jquery验证插件验证数组输入-为第一个输入添加一个错误


<form id="jvalidate" name="frmenquiry_package" class=""  action="#" method="post" >
<input type="text" name="reg_number[]" id="reg_number_1" value="" class="jsrequired form-control" />
<input type="text" name="reg_number[]"  id="reg_number_2" value="" class="jsrequired form-control"/>
<input type="text" name="reg_number[]"  id="reg_number_3" value="" class="jsrequired form-control" />
<input name="submit" value="Submit" type="button" id="submit"  onClick="javascript:funSave_contact_enquiry();">
</form>



function funSave_contact_enquiry(){
if ($('#jvalidate').valid()) {
$("#submit").attr('disabled',true);

alert('Success');
}
}


<script type="text/javascript" src="<?php echo base_url();?>site/js/jquery.validate.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>site/js/additional.js"></script>

我有以下表单。我正在尝试使用jquery验证插件验证输入。我试过一些代码,但不起作用。

当我点击为第一个输入#reg_number_1添加一个错误时,只有其他字段没有突出显示

我只做了测试所需的第一个输入,可以很好地使用cdn:

<html>
<head>
<script>
function funSave_contact_enquiry(){
if ($('#jvalidate').valid({rules : { reg_number_1 : "required"}})) {
$("#submit").attr('disabled',true);
alert('Success');
} else {
alert('fail');
}
}
</script>
</head>
<body>
<form id="jvalidate" name="frmenquiry_package" class=""  action="#" method="post" >
<input type="text" name="reg_number[]" id="reg_number_1" value="" class="jsrequired form-control" required/>
<input type="text" name="reg_number[]"  id="reg_number_2" value="" class="jsrequired form-control"/>
<input type="text" name="reg_number[]"  id="reg_number_3" value="" class="jsrequired form-control" />
<input name="submit" value="Submit" type="button" id="submit"  onClick="javascript:funSave_contact_enquiry();">
</form>

<script src="https://code.jquery.com/jquery-3.3.1.js"
integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
crossorigin="anonymous"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.0/jquery.validate.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.0/additional-methods.js"></script>
</body>
</html>

相关内容

  • 没有找到相关文章

最新更新