用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();
        }
    );

上面粗體部分是核心代碼。

沒有什么,留些印記而已。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM