[英]jQuery: Plugin Validation, how do I validate a dozen or so different fields?
I'm using this: http://docs.jquery.com/Plugins/Validation/Methods/accept#extension 我正在使用这个: http : //docs.jquery.com/Plugins/Validation/Methods/accept#extension
I'm trying to alert the user to only upload PNGs, Jpgs, JPEGS and PDFs. 我正在尝试提醒用户仅上传PNG,Jpg,JPEG和PDF。 On the server end if they do attempt, it will not work. 在服务器端,如果他们尝试尝试,它将无法正常工作。 On the user end I want to alert them what they are doing is false. 在用户端,我想提醒他们他们在做什么是错误的。 Try a different file type. 尝试使用其他文件类型。 Maybe even prevent them from submitting the form. 甚至可能阻止他们提交表单。
How do I get this to work with 1 dozen file fields? 如何使它与1打文件字段一起使用?
code: 码:
$("#fileForm").validate({
rules: {
yourFileFieldNameHere: {
required: false,
accept: "png,jpg,jpeg,pdf"
}
}
});
I'm assuming the yourFileFieldNameHere is the "name=" of the input field as thats the only parameter that works. 我假设yourFileFieldNameHere是输入字段的“ name =”,因为那是唯一起作用的参数。 I've tried to use the ID name. 我尝试使用ID名称。
Any suggestions? 有什么建议么?
Revised the answer, i missed the info about a dozen fields. 修改了答案,我错过了有关十几个领域的信息。 Try adding a rule for the dozen fields like this: 尝试为十几个字段添加规则,如下所示:
$("#fileForm").validate({
rules: {
//any other rules go here
}
});
$('.your-dozen-fields-selector').rules("add", {
required: false,
accept: "png,jpg,jpeg,pdf"
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.