博主就边讲边上代码吧。以往对表单当中的判空验证通常是失焦burl()和聚焦focus()事件进行操作,这是很久的一种方式;今天博主就分享一下比较新式一点的:
<td class="bggrayLeft30"><input type="text" id="bioName" datatype="*" nullmsg="请输入药品名称!"
name="bioName" class="text184" maxlength="10" /></td>
上述代码,当中的datatype="*"就是在你提交的时候进行判断input</>不能为空,nullmsg的红字就会出现在其旁;
看下面代码,关键
$(function () {
var action_form = $("#action_form").Validform({
tiptype : 3,//
label : ".label",
showAllError : true,
postonce : true,
btnSubmit : "#save",
ajaxPost : true,
beforeSubmit : function(curform) {
var start = true;
return start;
},
callback : function(data) {
if (data.ContractRoot.RspType == 1) {
layer.alert(data.ContractRoot.RspDesc,{icon:1},function(){
cReload();
});
} else {
layer.alert(data.ContractRoot.RspDesc,{icon:2});
}
$("#submit").removeAttr("disabled");
},
error : function() {
layer.alert("农药新增异常",{icon:2});
$("#submit").removeAttr("disabled");
},
dataType : "json"
});
});
当你提交的时候,前端界面如果做了第一片区代码,如果你没填,那么错误就会报出来,此时如果你的页抛出自定义异常throw new BussinessExcepton(自定义异常),那么前端界面接受也会抛出!