拥有一个属于自己的javascript表单验证插件(2)

<link type="text/css" href="https://www.jb51.net/~/Scripts/SimpoValidate.css" /> <script type="text/javascript" src="https://www.jb51.net/~/Scripts/jquery-1.8.2.js"></script> <script type="text/javascript" src="https://www.jb51.net/~/Scripts/ValidateUtil.js"></script>

2、表单HTML代码(部分代码):

<table cellpadding="0" cellspacing="0"> <tr> <td> <input value="" type="text" /> <span rule="int" msg="可为空,请填写正整数"></span> </td> </tr> <tr> <td> <input value="" type="text" /> <span rule="number" msg="必填,请填写数字"></span> </td> </tr> <tr> <td> <select> <option value="-1">==请选择==</option> <option value="1">是</option> <option value="2">否</option> </select> <span rule="^(?!-1$).+$" msg="必选"></span> </td> </tr> <tr> <td> <input value="1" type="checkbox" /> <span>多</span> <input value="2" type="checkbox" /> <span>少</span> <span rule="" msg="必选" to="a"></span> </td> </tr> <tr> <td> <input value="1" type="radio" /> <span>狗</span> <input value="2" type="radio" /> <span>猫</span> <span rule="" msg="必选" to="b"></span> </td> </tr> <tr> <td> <textarea cols="20" rows="5"></textarea> <span rule="^(.|\n){5,100}$" msg="可为空,长度必须大于等于5小于等于100"></span> </td> </tr> </table>

3、执行验证JS代码:

//保存数据 function save() { if (SimpoValidate.valid()) { //执行验证 $("#frm").submit(); //提交表单 } }

效果图:

拥有一个属于自己的javascript表单验证插件

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgydss.html