-2
function checkforblank(){
if (document.getElementById('fname').value == "help","help ","HELP","HELP ") {
showText("#msg2", 'commands:', 0, 100);
showText("#msg3", '#1 MAIN, back to MAIN menu', 0, 100);
showText("#msg4", '#2 PORT, nav to PORT page', 0, 100);
showText("#msg5", '#3 ABOUT, nav to ABOUT page', 0, 100);
showText("#msg6", '#4 CONT, nav to CONTACT page', 0, 100);
showText("#msg7", '#5 STOP, stop all', 0, 100);
//(document.getElementById('textarea').document.write('jajajajajjaja'());
return false;
}
else if (document.getElementById('fname').value == "main","main ","MAIN","MAIN "){
alert('hello');
}
else{
alert('error');
return false;
}
}
我else if語句可犯規執行代碼,而是它的代碼中的if語句..如果其他人如果不工作「的Javascript」
我相信這是因爲你的if語句不是檢查集合中是否包含值的適當方法...在[確定數組是否包含值]上查看此問題(http://stackoverflow.com/questions/1181575/javascript-determine-whether- an-array-contains-a-value) – user3334690
[逗號運算符](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator)不創建值=='來檢查。爲此,你需要一個'Array'來進行搜索,比如「[確定字符串是否在JavaScript中列表]」(http://stackoverflow.com/questions/2430000/determine-if-string-is -in-列表中的JavaScript)「。 –