实际上,我尝试使用这个url进行jquery图像文件验证,但它不是working.could,请您验证并通知我?
点击这里:https://github.com/snyderp/jquery.validate.file
<form method="post" enctype="multipart/form-data" id="upload_form">
<input type="file" name="example_file" name="example_file">
<button type="submit">Upload</button>
</form>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>
<script>
$(function () {
$("#upload_form")
.validate({
rules: {
example_file: {
fileType: {
types: ["text", "gzip", "zip"]
},
maxFileSize: {
"unit": "KB",
"size": 100
},
minFileSize: {
"unit": "KB",
"size": "10"
}
}
});
});
</script>发布于 2015-01-22 15:09:04
您希望使用扩展,所以只包含jquery和jquery.validate是不够的。因此,也包括插件下载插件。(我知道这个例子中缺少它)
最后的解决方案应该是:
<form method="post" enctype="multipart/form-data" id="upload_form">
<input type="file" name="example_file" name="example_file">
<button type="submit">Upload</button>
</form>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>
<script src="jquery.validate.file.js"></script>
<script> $(function () {
$("#upload_form")
.validate({
rules: {
example_file: {
fileType: {
types: ["text", "gzip", "zip"]
},
maxFileSize: {
"unit": "KB",
"size": 100
},
minFileSize: {
"unit": "KB",
"size": "10"
}
}
});
});
</script>编辑:测试jsfiddle中的上传功能并不是最好的主意,因为它一般不允许文件上传。
发布于 2015-01-22 17:16:03
没有这样的规则称为fileType,maxFileSize和minFileSize作为jQuery验证插件的一部分。你需要写你自己的规则或者https://github.com/snyderp/jquery.validate.file。
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>
<!--// need to include this one too //-->
<script src="jquery.validate.file.js"></script>你还有一个失踪的关闭支架..。
$("#upload_form").validate({
rules: {
example_file: {
fileType: {
types: ["text", "gzip", "zip"]
},
maxFileSize: {
"unit": "KB",
"size": 100
},
minFileSize: {
"unit": "KB",
"size": "10"
}
} // <- THIS one was missing
}
});https://stackoverflow.com/questions/28091620
复制相似问题