我试图根据单选按钮的onlcik隐藏字段,但该字段不起作用。还请建议如果我想在单个onclick上隐藏字段组。.我不能在表内使用div,并且我也尝试过tbody标签,但仍然无法正常工作
<head>
<title>Insert title here</title>
<script language=javascript>
function hide() {
var div_ref = document.getElementsByTagId("trr");
div_ref.style.visibility = "hidden";
}
function show() {
var div_ref = document.getElementById("trr");
div_ref.style.visibility = "visible";
}
</script>
</head>
<body onload="hide()">
<h1> Translate HSM</h1>
<form action="" method="post">
<table style="with: 50%">
<tr id="trr" >
<td >Enter HSM IP Address</td>
<td><input type="text" name="ip_address" /></td>
</tr>
<tr>
<td>Please Select Option for Read the HSM keys</td>
<td><input type="radio" name="readOption" value="manual" onclick="hide()">Enter keys Manually</td>
</tr>
<tr>
<td></td>
<td><input type="radio" name="readOption" value="DB" onclick="show()">Read HSM Keys from DB</td>
</tr>
</table>
</form>
答案 0 :(得分:0)
语句getElementsByTagId
上是否有错字?应该getElementById
吗?
function hide() {
var div_ref = document.getElementById("trr");
div_ref.style.visibility = "hidden";
}
function show() {
var div_ref = document.getElementById("trr");
div_ref.style.visibility = "visible";
}
<body onload="hide()">
<h1> Translate HSM</h1>
<form action="" method="post">
<table style="with: 50%">
<tr id="trr">
<td>Enter HSM IP Address</td>
<td><input type="text" name="ip_address" /></td>
</tr>
<tr>
<td>Please Select Option for Read the HSM keys</td>
<td><input type="radio" name="readOption" value="manual" onclick="hide()">Enter keys Manually</td>
</tr>
<tr>
<td></td>
<td><input type="radio" name="readOption" value="DB" onclick="show()">Read HSM Keys from DB</td>
</tr>
</table>
</form>
</body>