我遇到了這個函數的問題,第一部分被稱爲罰款,但在第一個if語句之後沒有其他任何東西被調用。我已經使用JSfiddle,但它不能確定一個嚴重的問題。Javascript函數的第一部分被稱爲
我通常使用PHP不是JS,所以我想知道是否有簡單的東西,我在這裏失蹤?
function validatequestion(form){
var e = document.getElementById("chooseqtype");
var strQtype = e.options[e.selectedIndex].value;
if(strQtype == "default"){
alert("Please select a question type");
return false;
}
if(strQtype == "textquestion"){
fail = validatetextq(form.textquestiondesc.value)
if(fail == "") return true
else {
alert(fail);
return false;
}
}
if(strQtype == "videoquestion"){
fail = validatevideoq(form.videoquestiondesc.value)
if(fail == "") return true;
else {
alert(fail);
return false;
}
}
//everything above works, after this point nothing seems to get called
var a = document.getElementById("chooseatype");
var strAtype = a.options[a.selectedIndex].value;
if(strAtype == "textanswer"){
//get the value of the number of text answers select box
var t = document.getElementById("choosetextnumber");
//put the value in variable strQtype
var strTextno = t.options[t.selectedIndex].value;
if(strTextno == "2tanswers"){
fail = validatetexta1(form.textanswer1.value)
fail += validatetexta2(form.textanswer2.value)
if(fail == "") return true;
else {
alert(fail);
return false;
}
}
}
}
你從第一個返回false if – 2013-02-21 13:45:14
NITPICK:使用else if! – epascarello 2013-02-21 13:45:27
你究竟在用這段代碼實現什麼? – Manuel 2013-02-21 13:47:01