2012-09-12 122 views

回答

0

此JavaScript功能確認用戶選擇了要上傳的文件。如果用戶沒有選擇文件,則該功能會顯示一條錯誤消息。

<script type="text/javascript"> 
    function checkForFile() { 
    if (document.getElementById('file').value) { 
    return true; 
    } 
    document.getElementById('errMsg').style.display = ''; 
    return false; 
    } 
</script> 

    <form action="URL?nexturl=http%3A%2F%2Fwww.example.com" method="post" 
    enctype="multipart/form-data" onsubmit="return checkForFile();"> 
    <input id="file" type="file" name="file"/> 
<div id="errMsg" style="display:none;color:red"> 
    You need to specify a file. 
</div> 
<input type="hidden" name="token" value="TOKEN"/> 
    <input type="submit" value="go" /> 
    </form> 
+0

感謝您的答覆,但在我的Android應用程序按鈕選擇文件不允許我選擇文件,並始終顯示錯誤。我是否需要在清單文件中添加任何額外的權限,以便啓用選擇文件按鈕 –

相關問題