我正在尝试通过 jQuery validate 验证 JSF 照片上传,但它不起作用。形式 :
<h:form id="uploadForm" name="uploadForm" enctype="multipart/form-data">
<table>
<tr>
<h:outputText for="file" value="Select Photo : " />
<t:inputFileUpload id="file1" name="file1" value="#{companyService.uploadedFile}" required="true" />
<h:message for="file" style="color: red;" />
</tr>
<tr>
<td></td>
<h:commandButton value="Upload" styleClass="add" action="#{companyService.uploadPhoto}" />
<h:message for="uploadForm" infoStyle="color: green;" errorStyle="color: red;" />
</tr>
</table>
</h:form>
脚本 :
<script type="text/javascript">
$(document).ready(function(){
//$('textarea').elastic();
$("#uploadForm").validate({
rules: {
file1: {
required: true,
accept: "jpg|gif|png|jpeg"
}
},
messages: {
file1: "jpg,gif,png,jpeg extensions are allowed"
}
});
})
</script>
我也导入了 jQuery 库...