试图隐藏一个项目 block ,以便在单击特定文本框时显示, 它适用于第一个项目并且不会影响其余项目,我需要帮助才能在页面加载时隐藏另一个 id,然后在最接近它的文本框和 id =Control
<html>
<body>
<table>
<tr>
<td><label>Approved Within 24HRS:</label></td>
<td><input name = "LLC_Veri_Approved" type = "text" size = "20" /></td>
</tr>
<tr>
<td><label>Not Approved:</label></td>
<td><input id = "control" name = "LLC_Veri_NotApproved" type = "text" size = "20" /></td>
</tr>
</table>
<h4>Number Of Verifications(LLC) Not Approved Reasons</h4>
<table id="Rtable">
<tr>
<td><label>No Receipt Attached:</label></td>
<td><input name = "LLC_No_Receipt" type = "text" size = "20" /></td>
</tr>
<tr>
<td><label>No Stamp Duty:</label></td>
<td><input name = "LLC_No_Stamp" type = "text" size = "20" /></td>
</tr>
</table>
<table>
<tr>
<td><label>Approved Within 24HRS:</label></td>
<td><input name = "LLC_Veri_Approved" type = "text" size = "20" /></td>
</tr>
<tr>
<td><label>Not Approved:</label></td>
<td><input id = "control" name = "LLC_Veri_NotApproved" type = "text" size = "20" /></td>
</tr>
</table>
<h4>Number Of Verifications(BN) Not Approved Reasons</h4>
<table id="Rtable">
<tr>
<td><label>No Receipt Attached:</label></td>
<td><input name = "BN_No_Receipt" type = "text" size = "20" /></td>
</tr>
<tr>
<td><label>No Stamp Duty:</label></td>
<td><input name = "BN_No_Stamp" type = "text" size = "20" /></td>
</tr>
</table>
<table>
<tr>
<td><label>Approved Within 24HRS:</label></td>
<td><input name = "IT_Veri_Approved" type = "text" size = "20" /></td>
</tr>
<tr>
<td><label>Not Approved:</label></td>
<td><input id = "control" name = "IT_Veri_NotApproved" type = "text" size = "20" /></td>
</tr>
</table>
<h4>Number Of Verifications(IT) Not Approved Reasons</h4>
<table id="Rtable">
<tr>
<td><label>No Receipt Attached:</label></td>
<td><input name = "IT_No_Receipt" type = "text" size = "20" /></td>
</tr>
<tr>
<td><label>No Stamp Duty:</label></td>
<td><input name = "IT_No_Stamp" type = "text" size = "20" /></td>
</tr>
</table>
</body>
<script type="text/javascript">
$(document).ready(function(){
//trying to hide all the tables with id=Rtable but works only for the first
$('#Rtable').hide();
//when you click on any of the textboxes with id = control
$('#control').on('click', function(){
$('#Rtable').show();
});
});
</script>
</html>
最佳答案
Id 必须是唯一的,对于 control
和 Rtable
元素使用类而不是 ids:
<input class="control" name="IT_Veri_NotApproved" type="text" size="20" />
JS:
$('.control').on('click', function () {
$(this).closest('table').nextAll('.Rtable:first').show();
});
演示:http://jsfiddle.net/3ctgnmLy/
关于javascript - 试图隐藏一个项目 block ,以便在单击特定文本框时显示,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27959053/