我正在尝试制作一些项目,我希望在我选择专家按钮时显示一个文本框,而当我单击学习者按钮时不显示文本框....
我已经编写了这段代码,但无法解决问题...请帮助...
<html>
<head>
<script language="javascript">
function toggleContent(showHideDiv, switchTextDiv) {
var text = document.getElementById(showHideDiv);
var ele = document.getElementById(switchTextDiv);
var rad_val='';
for (var i=0; i < document.text.role.length; i++)
{
if (document.text.role[i].checked)
{
rad_val = document.text.role[i].value;
}
}
if(rad_val=='learner'){
ele.style.display = "block";
}
else {
ele.style.display = "none";
}
}
</script>
</head>
<body>
<table>
<tr >
<td ><option value="1"> 1 </option>
</td>
<td> Role </td>
<form id="form1">
<td><label>
<input type="radio" name="role" value='learner' onClick="toggleContent('form1','div1')" >
Learner </label>
</td>
<td><label>
<input type="radio" name="role" value='expert' onClick="toggleContent('form1','div1')" >
Expert </label>
</form>
<td ><div ID="div1" align=right style="display:none;">
<label class="labell labelUser" >why?</label>
<textarea name="description" align="right" id="description" cols="40" rows="5" class="inputbox">Why?</textarea>
<span id="descriptionError" class="notifyForUser" spanError></span> </div></td>
</tr>
<tr >
<td ><option value="2"> 2 </option>
</td>
<td> Role </td>
<form id="form2">
<td><label>
<input type="radio" name="role" value='learner' onClick=toggleContent('form2','div2') >
Learner </label>
</td>
<td><label>
<input type="radio" name="role" value='expert' onClick=toggleContent('form2','div2') >
Expert </label>
</td>
</form>
<td ><div ID="div2" align=right style="display:none;">
<label class="labell labelUser" >why?</label>
<textarea name="description" align="right" id="description" cols="40" rows="5" class="inputbox">Why?</textarea>
<span id="descriptionError" class="notifyForUser" spanError></span> </div></td>
</tr>
</table>
</body>
</html>