此表單具有隱藏的textara和可見的文本框。我想換這些元素的可見性,如果選擇「d:」被選中,但不知道如何正確地檢查其單選按鈕,在任何給定的時間進行檢查:通過無線電選擇的切換元素可見性
<script language="JavaScript" type="text/javascript">
function unhide(event) {
event = event || window.event ;
target = event.target || event.srcElement;
if(target.value === "D:") {
if(target.checked) {
document.getElementByName('tarea').style.display='';
document.getElementByName('tbox').style.display='none';
}
}else {
if(target.checked) {
document.getElementByName('tarea').style.display='none';
document.getElementByName('tbox').style.display='';
}
}
}
</script>
</head>
<body>
<form method="get" action="/cgi-bin/form.cgi" enctype="application/x-www-form-urlencoded">
<input type="radio" name="opttype" value="A:" onclick="unhide(event)" />A:
<input type="radio" name="opttype" value="B:" onclick="unhide(event)" />B:
<input type="radio" name="opttype" value="C:" checked="checked" onclick="unhide(event)" />C:
<input type="radio" name="opttype" value="D:" onclick="unhide(event)" />D:
<br><input type="tbox" name="event" />
<br><textarea name="tarea" rows="8" cols="80" style="width:580;height:130;display:none;"></textarea>
你先生,是男人。 – Mose 2010-07-04 10:52:14