jQuery验证接受方法-TypeError:无法读取未定义的属性“调用" [英] jquery validate accept method - TypeError: Cannot read property 'call' of undefined
本文介绍了jQuery验证接受方法-TypeError:无法读取未定义的属性“调用"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用validate插件检查上传文件的类型.
I want to check the upload file type using the validate plugin.
但是我收到以下错误消息:
But I got the following error message:
Uncaught TypeError: Cannot read property 'call' of undefined.
Exception occurred when checking element file, check the 'accept' method.
这是我的表格.
<form id="upload" enctype="multipart/form-data">
<div class="control-group">
<div class="controls">
<input id="file" name="file" type="file">
</div>
<div class="form-group">
<button class="btn btn-primary" onclick="Submit()" type="button">Submit</button>
</div>
</div>
</form>
这是我的JavaScript:
And here is my JavaScript:
var Submit=function(){
var validator = $('#upload').validate({
rules:{
file: {
required: true,
accept: "audio/*, video/*"
}
},
message: {
file:"Invalid file type"
}
});
validator.form();
}
推荐答案
要使用"accept"
方法,您需要包括jQuery Validate其他方法文件.只需在验证文件之后添加它即可:
To use the "accept"
method you'll need to include the jQuery Validate additional methods file. Simply include it after your validate file:
<script src="http://jqueryvalidation.org/files/dist/jquery.validate.min.js"></script>
<script src="http://jqueryvalidation.org/files/dist/additional-methods.min.js"></script>
然后尝试像这样启动验证器:
Then try initiating your validator like this instead:
$(document).ready(function(){
$("#upload").validate({
...settings...
});
});
然后从按钮中删除onClick
和type="button"
属性.
And remove the onClick
and type="button"
attribute from your button.
以下是文档:
http://jqueryvalidation.org/validate/
这篇关于jQuery验证接受方法-TypeError:无法读取未定义的属性“调用"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文