用JS怎么判断上传文件控件是否未选择文件
发布网友
发布时间:2022-04-25 11:53
我来回答
共1个回答
热心网友
时间:2022-04-25 13:22
这是html代码
<form name="form1" action="uploadPosdetailFile.html" method="post" ENCTYPE="multipart/form-data">
<div class="form" >
<p>
<span class="req"><input id="startDateTxt" name="startDateTxt" class="field size4" title="Enter the date" /></span>
<label>Start Date: <span>(Date format:MM/dd/yyyy,eg:01/01/2014)</span></label>
</p>
<p>
<span class="req"><input id="endDateTxt" name="endDateTxt" class="field size4" title="Enter the date" /></span>
<label>End Date: <span>(Date format:MM/dd/yyyy,eg:12/25/2014)</span></label>
</p>
<p>
<span class="req"><input type="file" name="uploadFileCtrl" class="field size4" title="Choose the file" /></span>
<label>Upload file: <span>(click browse to choose)</span></label>
</p>
</div>
<div class="buttons">
<input id="queryBtn" type="button" class="button" value="Submit" />
</div>
</form>
下面是验证,jquery写的
$("#queryBtn").click(
function(){
......
var s=document.form1.uploadFileCtrl.value;
if(s==""){
alert("Please choose a posdetail file.");
document.form1.uploadFileCtrl.focus();
return;
}
showLoadingWnd('Uploading,please wait...');
document.form1.submit();
}
);