当我点击No
时,文本框应该隐藏但不会发生。当我将div
放在我调用td
事件的onclick
内时,它正在运行。
<!DOCTYPE html>
<html>
<head>
<script>
src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("#btn1").click(function(){
$("#data").show();
});
$("#btn2").click(function(){
$("#data").hide();
});
});
</script>
</head>
<table>
<tr>
<th>Table</th>
<td>
<input type="radio" id="btn1" name="gate" value="N" checked>Yes</input>
<input type="radio" id="btn2" name="gate" value="E" >No</input>
</td>
</tr>
<div id="data" style="padding-top: 10px">
<tr>
<th>GATE</th>
<td><input type="text" name="gate1" value=gate1 size="20"></td>
</tr>
</div>
</table>
</html>
答案 0 :(得分:1)
看看
$(document).ready(function(){
$("#btn1").click(function(){
$("#data").show();
});
$("#btn2").click(function(){
$("#data").hide();
});
});
&#13;
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js">
</script>
</head>
<table>
<tr>
<th>Table</th>
<td>
<input type="radio" id="btn1" name="gate" value="N" checked>Yes</input>
<input type="radio" id="btn2" name="gate" value="E" >No</input>
</td>
</tr>
<tr id="data">
<th>GATE</th>
<td><input type="text" name="gate1" value=gate1 size="20"></td>
</tr>
</table>
</html>
&#13;
答案 1 :(得分:1)
你将div
放在桌子内 - 你不应该这样做。试试这段代码:
$(document).ready(function() {
$("#btn1").click(function() {
$(".data").show();
});
$("#btn2").click(function() {
$(".data").hide();
});
});
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<table>
<tr>
<th>Table</th>
<td>
<input type="radio" id="btn1" name="gate" value="N" checked/>Yes
<input type="radio" id="btn2" name="gate" value="E" />No
</td>
</tr>
<tr class="data" style="padding-top: 10px">
<th>GATE</th>
<td>
<input type="text" name="gate1" value=gate1 size="20">
</td>
</tr>
<tr class="data" style="padding-top: 10px">
<th>GATE</th>
<td>
<input type="text" name="gate2" value=gate2 size="20">
</td>
</tr>
</table>
</html>