我正在使用 将以下规则添加到现有的 jQuery Validate 脚本中extension
,但是这个片段会导致它中断并且根本无法验证。我之前和之后都尝试过逗号的所有可能组合,我也尝试过使用accept
mimetypes 的方法,但到目前为止没有任何效果。如果我注释掉这个片段(以及它前面的注释),代码可以完美运行,但是添加它会导致它中断。
这是一个 jsFiddle的代码原样(不起作用),这是一个完全相同的代码,除了代码片段被注释掉(工作正常)。
片段本身:
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);
}
}
});
});