我使用Jquery驗證器「http://jqueryvalidation.org/」驗證了我的表單。 我在驗證「<input type="file" />
」字段時發生問題,其「required: true,
」驗證正在運行,當我接受錯誤的文件類型時,會引發錯誤。但在「IE和Chrome」中,如果我選擇了正確的文件格式,它仍然會給出錯誤,儘管它在Firefox中正常工作。<input type =「file」/>文件格式驗證在Chrome和IE中不起作用
創造了小提琴太...這是怎麼回事正好爲我工作: http://jsfiddle.net/aasthatuteja/v6x8P/
**如果您在Chrome & IE檢查它會給這個問題,但如果你在Firefox檢查它會工作,並會提供「已提交」的aert!
請在以下提到的代碼: -
jQuery的
<script src="~/Scripts/js/jquery.validate.js"></script>
<script src="http://jquery.bassistance.de/validate/additional-methods.js"></script>
<script>
$().ready(function() {
// validate signup form on keyup and submit
$("#deploymentUploadForm").validate({
rules:{
File: {
required: true,
accept: "zip"
}
},
messages:{
File: {
required: "This field is mandatory!",
accept: "Accepts only zip file!"
}
}
});
});
</script>
HTML
<form action="~/Deployment/FileUpload" name="deploymentUploadForm" id="deploymentUploadForm" enctype="multipart/form-data" method="post">
<h1>Deployment</h1>
<p>
<input type="file" name="File" accept="application/zip">
</p>
<div role="button" class="marginTop50 marginBottom">
<p>
<input type="submit" id="getDeploymentList" value="Upload" class="active" >
</p>
</div>
</form>
的onsubmit JQUERY
$("#getDeploymentList").click(function() {
if ($("#deploymentUploadForm").valid()) {
$("#deploymentUploadForm").submit();
$('#stepSummary').empty();
$.loader({
className: "blue-with-image",
content: 'Please wait...Your request is being processed!'
});
};
});
請讓我知道如果你需要任何其他信息。
感謝adavace!
@TusharGupta:不,它們是一樣的,甚至是$(功能)... – dandavis
@dandavis哦對不起,我知道了 –
你在OS X上的Chrome 29中工作正常。你測試哪個IE?由於驗證使用HTML5文件API,因此它將在IE9及更低版本中失敗[請參閱(http://caniuse.com/#feat=fileapi))。 – insertusernamehere