我将下面的规则添加到使用extension
的现有jQuery验证脚本中,但是此片段导致它断开并且根本不验证。我已经尝试过所有可能的逗号组合,并且我也尝试了使用mimetypes的accept
方法,但迄今为止没有任何工作。如果我注释掉这段代码(以及之前的行注释),代码完美地工作,但添加它会导致代码中断。jQuery验证扩展方法不起作用
Here's a jsFiddle与代码原样(不起作用),和here's one具有完全相同的代码,除了片段被注释掉(工作正常)。
的片段本身:
form1upload: {
extension: "jpg|jpeg|pdf|doc|docx|png"
}
的完整代码:
jQuery(document).ready(function() {
jQuery("#grantapp").validate({
errorClass:"errorlabels",
rules: {
form1name: "required",
form1building: "required",
form1position: "required",
form1phonex: "required",
form1besttime: "required",
form1projtitle: "required",
form1benefit: "required",
form1timeframe: "required",
form1relevance: "required",
form1description: "required",
form1amount: "required",
form1acceptchk: "required",
form1upload: {
extension: "jpg|jpeg|pdf|doc|docx|png"
}
},
messages: {
form1name: "You must enter your name.",
form1building: "You must enter your building.",
form1position: "You must enter your position.",
form1phonex: "You must enter your phone extension.",
form1besttime: "You must enter the best time to contact you.",
form1projtitle: "You must give your project a title.",
form1benefit: "You must enter the number of students who will benefit.",
form1timeframe: "You must enter a time frame for this project.",
form1relevance: "<br />You must state how this project is relevant to education.",
form1description: "<br />You must provide a description of your project.",
form1amount: "You must enter a requested amount.",
form1acceptchk: "<span style=\"position:relative;top:-10px;\">You must accept the terms.</span>",
form1upload: "You may not upload this type of file."
},
errorPlacement: function (error, element) {
if (element.attr("name") == "form1acceptchk") {
error.insertAfter("#tbl1");
} else {
error.insertAfter(element);
}
}
});
});
的语法看起来是正确的给我。 – 2013-03-16 00:33:28
这就是我的想法。我已经反复检查过,看起来对我很好。具体的扩展部分看起来也是正确的,[根据文档](http://docs.jquery.com/Plugins/Validation/CustomMethods/extension#extension)。 – vaindil 2013-03-16 00:35:19
经过多个版本的插件测试,它确实显得破损http://jsfiddle.net/ult_combo/4jMHZ/ – 2013-03-16 00:42:49