公用js
(function($) { $.fn.formVaild = function() { var _this = $(this); _this.find("[notEmpty]").each(function() { var _ths = $(this); var val = _ths.val(); var txt = _ths.attr("notEmpty")||_ths.attr("placeholder"); if (txt&&!val) { alert(txt); throw new Error(txt); } }); } })(jQuery);
页面中
<input name="writerNumber" placeholder="请输入账号" notEmpty value="${number}" >
调用
//提交表单时,表单验证 $("form").formVaild();