Jquery批量判断是否为空,是否为数字

$(document).ready(function () { $("#btnSubmit").click(function () { return isEmpty("") && isNum(); }); }); //判断是否全部为空 function isEmpty(expression) { var arry; if (typeof (expression) == "undefined") { arry = $(".isEmpty"); } else { arry = $(expression); } for (i = 0; i < arry.length; i++) { var cur = $(arry[i]); if (cur.val() == "") { alert(cur.attr("info") + "不能为空!"); cur.focus(); return false; } } return true; } //判断是否全是整数 function isNum(expression) { var arry; if (typeof (expression) == "undefined") { arry = $(".isNumber"); } else { arry = $(expression); } for (i = 0; i < arry.length; i++) { var cur = $(arry[i]); if (!/^\d+$/.test(cur.val())) { alert(cur.attr("info") + "必须是整数!"); cur.focus(); return false; } } return true; }

你可能感兴趣的:(Jquery批量判断是否为空,是否为数字)