用JS怎么判断上传文件控件是否未选择文件
1个回答
展开全部
这是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();
}
);
<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();
}
);
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |