我在 html 页面中有按钮单击事件,我在其中调用 PHP 文件。在 php 中,我有两个 div,我想根据我的复选框显示隐藏... 现在它显示两个复选框和显示 div。但我想仅在用户选中第一个复选框时加载显示 div 我怎样才能实现这一点?请帮忙。这里是 PHP 代码
<div id="dialog_title">
<input type="checkbox" name="First" value="First">
First List<br>
<input type="checkbox" name="Second" value="Second">Second
</div>
<div id="Show div">
<table>
<tr>
<th> Name </th>
<th> Address </th>
</tr>
<?php
foreach ( $deviceArr as $device) {
$id = $device['id'];
$name = $device ['name'];
$Address = $device['address'];
?>
<tr class="font1">
<td> <input type="text" class="g_input_text" name="name[]" value="<?php echo $name; ?>" /> </td>
<td>
<input type="text" class="g_input_text" name="address[]" value="<?php echo $Address; ?>" />
<input type="hidden" name="id[]" value="<?php echo $id; ?>" />
</td>
</tr>
<?php
}
?>
</table>
</div>
最佳答案
加载页面时,隐藏我名为first_list_bx
的show div
,并为第一个复选框提供一个ID作为first_chk_bx
,如下所示:
<input type="checkbox" name="First" value="First" id="first_chk_bx">
<div id="first_list_bx" style="display:none;">
//code
</div>
然后使用jquery来检测复选框的 checkin 并显示first_list_bx
,例如:
$('#first_chk_bx').click(function() {
if($(this).is(":checked")){
$("#first_list_bx").show();
}
else{
$("#first_list_bx").hide();
}
});
关于javascript - div 在 PHP 中从复选框隐藏和显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21775778/