首页 > 代码库 > 用JS怎么判断上传文件是否为空

用JS怎么判断上传文件是否为空

页面代码:

    <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>

 

验证代码:

    $("#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();        }    );

上面粗体部分是核心代码。

没有什么,留些印记而已。

用JS怎么判断上传文件是否为空