我有輸入表單來上傳您的檔案并提交該檔案(方法 = 發布)我需要檢查用戶是否上傳了影像。如果不是,則應顯示錯誤訊息并回傳 false。但在我的情況下 return false 不起作用
我的代碼
const jobs = document.getElementById("jobImage");
const error = document.getElementById("Error");
我的功能
function func(){
if(jobs.value < 1){
console.log("1")
error.style.display = "block";
error.textContent = "Pleas upload your image";
setTimeout(function(){ window.location.reload(); },5000);
return false
}
}
當我使用我的函式時,它回傳 true 而不是 false
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<button type="submit" value="Save" class="btn btn-default" id="save" onclick="func()"><a href="www.google.com">Go now</a></button>
</div>
</div>
</div>
此致
uj5u.com熱心網友回復:
您必須更改為:
if( jobs.files.length == 0 ){
...
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/369752.html
標籤:javascript html
