The example in this article describes jQuery's method of batch judging whether the text boxes in the form are empty. Share it with everyone for your reference, the details are as follows:
Method 1:
<script type="text/javascript"> /* * 批量验证表单非空 * 需要非空验证控件的样式class="mustadd" */ $(".mustadd").each(function(){ if($(this).val() == ''){ alert("该项不可为空!"); $(this).focus(); return false; } }) </script>
Method 2:
<script type="text/javascript"> //批量验证表单非空 function checkForm(arr){ for(var i=0;i<arr.length;i++){ if($("#"+arr[i][0]).val()==''){ alert(arr[i][1]); $("#"+arr[i][0]).focus(); return false; } } return true; }; //调用方式 var arr=new Array( new Array('userName','用户名不可为空!'), new Array('passwd','密码不可为空!'), )); if(!checkForm(arr)){ return false; } </script>
I hope this article will be helpful to everyone in jQuery programming.