2011-01-19 23 views
0

この動的HTMLブロックにスイッチ条件を含めるとします。どうやってやるの?動的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

http://www.w3schools.com/js/js_switch.asp

ここではいくつかのドキュメントがあります。

+0

スイッチケースの仕組みを知っています。しかし、私はこれが動的なHTMLブロックにどのように含めることができるかを知る必要があります – kiran

+0

satyaはあなたに感謝して、このwwith私を助けることができます – kiran

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 */ 
} 
関連する問題