我在网上到处都看,但无法解决这个问题。只需尝试使用addMethod创建自定义验证检查。但是我一直收到以下错误!
据我所知,我包括所需的插件!
错误:
jquery.validate.js:754 Uncaught TypeError:无法读取属性' call' 未定义的。检查元素注释时发生异常, 检查' nourl'方法
代码:
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.15.0/jquery.validate.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.15.0/additional-methods.min.js"></script>
<div class="container">
<div class="row">
<div class="twelvecol">
<form id="form" method="" action="">
<div class="row">
<div class="twelvecol">
<label for="name">Name</label>
<input type="text" id="name" name="name">
</div>
</div>
<div class="row">
<div class="twelvecol">
<label for="comments">Comments</label>
<input type="text" id="comments" name="comments">
</div>
</div>
</form>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$.validator.addMethod("nourl", function(value, element) {
console.log("hello");
return !/http\:\/\/|www\.|link\=|url\=/.test(value);
}, "No URL's" );
$("#form").validate({
rules: {
name: {
required: true
},
comments: {
nourl: true
}
},
messages: {
name: "Required Field",
comments: "No URL's"
}
});
});
</script>
答案 0 :(得分:2)
对于浪费的帖子很抱歉,这个插件在jQuery v1.7.1上不起作用。