As shown below:
//Based on the layer framework, references are made when verifying forms. Popup prompt errorfunction qxMsg(msgStr) { ({ type: 1, title: 'Prompt message', offset: '10%;', content: '<div style="padding: 20px 80px;">'+msgStr+'</div>', btn: 'closure', btnAlign: 'c', shade: 0.2, yes: function() { (); } }); }
The above is the encapsulated layer method, and the following is the verification combined with the form.
//Form Verificationfunction checkForm() { var err = ""; if(!$('input[name="ggName"]').val()) { err += "<br/>The name cannot be empty"; } if(!$('input[name="isId"]').val()) { err += "<br/>Space classification cannot be empty"; } if(err) { err = (5); qxMsg(err); return 0; } return 1; }
Just click the checkForm method before ajax submits the form, such as:
//Submit new datafunction addGgBaseModel() { var flag = checkForm(); if(flag == 0) return; var formData = new FormData(("myform")); ("SysType", "10101"); ("SysName", "qxPC"); ("ModuleName", "Specification Model"); $.ajax({ type: 'post', url: _URL_BASE + '/ggBaseModel/addGgBaseModel ', data: formData, cache: false, contentType: false, processData: false, dataType: 'json', success: function(retData) { (retData); if( == "1001") { qxMsg("Added successfully"); $(".layui-layer-btn0").click(function() { $('.modal-backdrop').remove(); $("#myModal").hide(); getGgBaseModel(); }) } else if( == "4004") { kickout(); } else { qxMsg(); } }, error: function(retData) { qxMsg("Error submitting data"); } }); };
The above method to use layer to achieve perfect form verification is all the content I share with you. I hope you can give you a reference and I hope you can support me more.