0

根据所选选项的类型,我希望显示 1 个或 3 个文本区域,即,如果选择了选项“mc”,我希望显示 3 个文本区域。我正在尝试在 Javascript 中执行此操作,但是每个选择的选项都会显示 3 个文本区域。我认为 JS 功能不起作用。您能否让我知道错误在哪里。

谢谢。

代码:

<head>           
    <link href="./css.css" rel="stylesheet" type="text/css" />
</head>
<body>          
    <h:form>                
        <script type="text/javascript"> 
              function selectans(qtype)  {                         
                if (qtype == "mc")
                {
                    alert("In MC type");
                    document.getElementById("formId:editor3").style.display = "block";
                    document.getElementById("formId:editor4").style.display = "block";
                    //document.form.editor3.disabled = false;
                    //document.form.editor4.disabled = false;                            
                } 
                else {

                    document.getElementById("formId:editor3").style.display = "none";
                    document.getElementById("formId:editor4").style.display = "none";
                    //document.form.editor3.disabled = true;
                    //document.form.editor4.disabled = true;
                }
              }                                                              
      </script>

       Question Type: 
       <h:selectOneMenu  id="qtype" value ="#{quizBean.qtype}" onchange="selectans(qtype) ">
           <f:selectItem id="desc" itemLabel="Descriptive Type" itemValue="desc" />
           <f:selectItem id="fill" itemLabel="Fill up the Blanks" itemValue="fill" />
           <f:selectItem id="mc" itemLabel="Multiple Choice" itemValue="mc"  />
           <f:selectItem id="tf" itemLabel="True/False" itemValue="tf" />
       </h:selectOneMenu>

       Question:                              <h:inputTextarea id="editor1" value="#{quizBean.question}" rows="20" cols="75" /> <br></br> 

       Answer:
           <h:inputText id ="editor2" value="#{quizBean.answerChoice2}"  />
           <h:inputText id ="editor3" value="#{quizBean.answerChoice2}"  />
           <h:inputText id ="editor4" value="#{quizBean.answerChoice3}"  />                                                         

            <h:commandButton value="Submit" action="#{quizBean.addQuestion}" />
</h:form>        

</body>

CSS:

root { 
    display: block;
}

.hide {
    display: none;
}
4

1 回答 1

1

你的事件函数应该是这样onchange="selectans('qtype') "的这样只有一个字符串作为参数传递

于 2013-02-19T05:42:06.383 回答