我想在此动态HTML块中包含切换条件。我怎么能这样做?
editQuestionBlockHTML=' <div class="addQuestionBlock" >'
+'<div class="selectQnLabel"><p class="selectQnLabel">Select a type of question</p>'
+'<p class="questionTypes">';
switch(questionType)
{
case "Radio":
editQuestionBlockHTML += +' <select id="EditQuestionType" onchange="changeQuestionType();">'
+' <option value="radioBtn" selected="selected">Radio Button</option>'
+' <option value="checkBox">Check Box </option>'
+' <option value="pullDownMenu">Pull Down Menu</option>'
+' <option value="ratingScale"> Rating Scale</option>'
+' <option value="commentBox"> Comment Box</option>'
+' <option value="singleTextBox"> Single Text Box</option>'
+' </select>';
break;
}
editQuestionBlockHTML+=+'</p></div>'
+'<div style="float:left;width:100%;">'
+' <p class="selectQnLabel">Enter Question</p>'
+' <p><textarea "EditQuestionTitle-'+questionId+'" class="inputBox" rows="4" cols="65" >'+questionText+'</textarea></p>'
+'<div style="clear:both;">'
+'</div>'
+'</div>'
+'<div style="float:left;width:100%;">'
+' <p class="selectQnLabel">Enter Choices (Each choice on a separate line)</p>'
+' <p><textarea id="editQuestionChoiceList-'+questionId+'" class="inputBox" rows="4" cols="65">'
+choicelist
+'</textarea></p>'
+'<div style="clear:both;">'
+'</div>'
+'</div>'
+'</div>'
+'</div>';
return editQuestionBlockHTML;
答案 0 :(得分:0)
答案 1 :(得分:0)
javascript中的“切换”条件非常简单:
switch(n){
case 1: // it's like: if(n == 1) ...
/* do stuff */
break; //really 'breaks' the switch and ignore everything else inside the switch
case 2:
case 3: //multiple matches ..it's like: else if(n == 2 || n == 3)
/* do stuff */
break;
default: //default code if no match has been found with your cases .. it's like the last "else" in your if .. else statement
/* do stuff */
}