分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow
也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!
通过$.fn 扩展jQuery方法
/** * 校验文本是否为空 * tips:提示信息 * 使用方法:$("#id").validate("提示文本"); * @itmyhome */$.fn.validate = function(tips){ if($(this).val() == "" || $.trim($(this).val()).length == 0){ alert(tips + "不能为空!"); throw SyntaxError(); //如果验证不通过,则不执行后面 }}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
使用
<form action=""> 姓名: <input type="text" id="name" name="name" /> 年龄:<input type="text" id="age" name="age" /> 地址:<input type="text" id="address" name="address" /> <input type="button" value="提交" onclick="submit();" /></form>
- 1
- 2
- 3
- 4
- 5
- 6
function submit(){ //调用validate() $("#name").validate("姓名"); $("#age").validate("年龄"); $("#address").validate("地址");}
- 1
- 2
- 3
- 4
- 5
- 6
作者:itmyhome