0
我已經寫了一個javascript函數來驗證文件輸入文件:JavaScript函數返回簡化版,正確
function valaidateform() {
var fileInput = document.getElementById('file');
message = "";
var file = fileInput.files[0];
var textType = /text.*/;
if (file.type.match(textType)) {
var reader = new FileReader();
reader.onload = function(e) {
filecontent = reader.result.trim();
var res = filecontent.split("\n");
lines = res.length;
if (!(filecontent.substring(0, 1) == ">")) {
alert("Not a proper file Fasta file");
return false;
}
}
reader.readAsText(file);
}
else {
alert("File not supported!");
}
alert("VAlidate function to end now")
return true;
}
//On form submit I call validateform() function
formrequest.submit(function() {
alert(valaidateform());
if (validationstatus == false) {
return false;
}
}
在我的表單提交的代碼,我調用這個函數來檢查文件validation.Function正確作爲工作我可以從函數獲取警報消息,但在Not a proper file Fasta file
之前顯示提示消息VAlidate function to end now
,並且函數始終返回true以致調用函數爲什麼這樣?我該如何解決這個問題?
謝謝你向我解釋原因,它真的爲我清除了理由,但是當我在這種情況下嘗試相同的代碼時,它返回undefined。 –
沒問題,看我的更新 –