我正在尝试设置 jQuery Validate依赖表达式,以便用户需要使用文本字段或上传文件,但此代码不起作用:这两个字段始终是必需的。我猜<input type="file">
不支持#id:empty
,但我可以用什么代替它?
Javascript:
jQuery(document).ready(function() {
jQuery("#form1iienom").validate({
errorClass:"errorlabels",
rules: {
form1apptext: {
required: "#form1upload:empty"
},
form1upload: {
required: "#form1apptext:empty",
extension: "jpg|jpeg|pdf|png|doc|docx"
},
},
messages: {
form1apptext: "You must either enter a reason for your nomination or upload a file.",
form1upload: {
required: "You must either enter a reason for your nomination or upload a file.",
},
}
});
});
HTML:
<form name="form1iienom" id="form1iienom" method="post" action="/applications/iie/review" enctype="multipart/form-data">
<textarea name="form1apptext" id="form1apptext"></textarea><br />
<br />
<em>(allowed file types are jpg, jpeg, pdf, png, doc, and docx; maximum file size is 3 MB)</em>
<input type="hidden" name="MAX_FILE_SIZE" value="3145728" />
<input type="file" name="form1upload" id="form1upload" /><br />
<input type="submit" value="Submit" />
</form>