做输入校验的时候如果你前端框架用的是bootstrap的话,首推bootstrapValidator校验方式,具体流程如下:
一、下载,导入js文件<link type="text/css" rel="stylesheet" href="${ctx}/components/validate/css/bootstrapValidator.css" /><script type="text/javascript" src="${ctx}/components/validate/js/bootstrapValidator.js"></script><script type="text/javascript" src="${ctx}/components/validate/js/language/zh_CN.js"></script>
二、$(表单id:)({message:"这里写默认提示信息";feedbackIcons:{valid:"glyphicon glyphicon-ok",invalid:"glyphicon glyphicon-remove",validating:"glyphicon glyphicon-refresh"}, fields: {inputName: {validators: {notEmpty: {message: "时间不能为空"},regexp: { regexp: /^[0-9]+$/ , message: "时间由数字组成" }, stringLength: {min: 1,max: 20,message: "角色名长度必须在1到20之间"}}} } )
网上有各种验证,当然有自定义验证,如上例中的时间由数字组成。
以上所述是小编给大家介绍的BootStrapValidator校验方式,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!