想要完成點擊radiobuttons中的按鈕后,顯示相應的試題的div,但是運行下面代碼不能完成需求,請問大神們可以幫一下嗎?
其中后臺傳輸的資料${sessionScope.questionType }的物件中有int型別的questionType_id、string型別的questionTypeName
<body>
<h2>請添加試題 ${sessionScope.questionNumber }</h2>
<jsp:useBean id="Question" class="com.yny.beans.Question" scope="request"/>
<form:form action="../teacher/addQuestion" method="post" modelAttribute="Question">
<!-- 設定試題屬于哪個試卷 -->
<form:hidden path="test_id" value="https://bbs.csdn.net/topics/${sessionScope.test.test_id }"/>
<!-- 選擇試題型別 -->
選擇試題型別:<form:radiobuttons path="questionType_id" id="questionType_id" items="${sessionScope.questionType }" itemValue="https://bbs.csdn.net/topics/questionType_id" itemLabel="questionTypeName" οnclick="divClick();"/><br>
<!-- 根據試題型別顯示相應的添加框 -->
<!-- 單選題 -->
<div id="ocq">
請輸入題干:<form:input path="qs" style="width: 400px;height: 40px;"/><br><br>
A選項:<form:input path="qa" style="width: 450px;height: 20px;"/><br><br>
B選項:<form:input path="qb" style="width: 450px;height: 20px;"/><br><br>
C選項:<form:input path="qc" style="width: 450px;height: 20px;"/><br><br>
D選項:<form:input path="qd" style="width: 450px;height: 20px;"/><br><br>
請輸入答案:<form:input path="QuestionAnswer" style="width: 300px;height: 20px;"/><br><br>
請輸入此試題的分數:<form:input path="QuestionScore" style="width: 200px;height: 20px;"/><br><br><br>
</div>
<!-- 多選題 -->
<div id="mcq">
請輸入題干:<form:input path="qs" style="width: 400px;height: 40px;"/><br><br>
A選項:<form:input path="qa" style="width: 450px;height: 20px;"/><br><br>
B選項:<form:input path="qb" style="width: 450px;height: 20px;"/><br><br>
C選項:<form:input path="qc" style="width: 450px;height: 20px;"/><br><br>
D選項:<form:input path="qd" style="width: 450px;height: 20px;"/><br><br>
E選項:<form:input path="qe" style="width: 450px;height: 20px;"/><br><br>
請輸入答案:<form:input path="QuestionAnswer" style="width: 300px;height: 20px;"/><br><br>
請輸入此試題的分數:<form:input path="QuestionScore" style="width: 200px;height: 20px;"/><br><br><br>
</div>
<!-- 判斷題 -->
<div id="tfq">
請輸入題干:<form:input path="qs" style="width: 400px;height: 40px;"/><br><br>
請輸入答案:<form:input path="QuestionAnswer" style="width: 200px;height: 20px;"/>【1代表對;0代表錯】<br><br>
請輸入此試題的分數:<form:input path="QuestionScore" style="width: 200px;height: 20px;"/><br><br><br>
</div>
<input type="submit" value="https://bbs.csdn.net/topics/提交"/>
</form:form>
<!-- 判斷是那種題型 -->
<script type="text/javascript">
function divClick(){
var show="";
var apm = document.getElementsById("questionType_id");
for(var i=0;i<apm.length;i++){
if(apm[i].checked)
show = apm[i].value;
}
switch (show){
case '1':
document.getElementById("ocq").style.display="block";
document.getElementById("mcq").style.display="none";
document.getElementById("tfq").style.display="none";
break;
case '2':
document.getElementById("ocq").style.display="none";
document.getElementById("mcq").style.display="block";
document.getElementById("tfq").style.display="none";
break;
case '3':
document.getElementById("ocq").style.display="none";
document.getElementById("mcq").style.display="none";
document.getElementById("tfq").style.display="block";
break;
default:
document.getElementById("ocq").style.display="none";
document.getElementById("mcq").style.display="none";
document.getElementById("tfq").style.display="none";
break;
}
}
</script>
</body>
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/69368.html
標籤:Web 開發
