【发布时间】:2022-01-18 07:39:04
【问题描述】:
所以,我正在尝试创建一个具有此操作的复选框:
- chkAll 复选框,一旦被勾选,所有其他复选框也会被勾选。
- 发生此操作时,将出现一个按钮。
然后,我试图实现的另一个动作是,如果两个或多个复选框(不包括 chkAll 框被勾选,同样的按钮也会出现。 这个按钮就像一个 zip 文件按钮,所以,只有勾选了多个复选框,才会出现(启用才能使用)。
目前我面临的错误是, 1.chkAll复选框需要双击才出现按钮。
2.当我取消单击 chkAll 复选框时,该按钮确实消失了,但其他 chckboxes 仍然打勾,他们认为也没有打勾。
3.当多于1个复选框被勾选时,按钮不会出现。
我是 php、jquery 的新手,因此非常感谢您的任何指导。 谢谢。
function toggleTick_Change() {
$('input[type=checkbox]').change(function() {
if ($("#chkAll").prop("checked")) {
$('input[type=checkbox]').prop('checked', $(this).prop("checked"));
$("#conditional-part").show();
} else if ($("#chkT").prop("checked")) {
if ($("#chkT").length > 1) {
$("#conditional-part").show();
} else {
$("#conditional-part").hide();
}
} else {
$("#conditional-part").hide();
}
});
}
#conditional-part {
display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<div class="content">
<div class="container">
<div id="page-container">
<div id="page-header">
<h3>Manage Deliveries</h3>
</div>
<div id="page-content">
<table align="center">
<tr id="conditional-part">
<td class="input-group " role="group" aria-label="..." style="width: 85px; margin-top: 2px;">
<input type="number" class="form-control input-xs" id="cpyCN{$rows.id}" name="cpyCN{$rows.id}" value="1" style="font-family: Raleway, Tahoma, Arial; font-size: 8pt; padding: 2px 2px 2px 10px;" placeholder="Copies" min="1" max="999" />
<span class="input-group-btn">
<button id="btnPrintCNTicked{$rows.id}" type="button" class="btn btn-primary btn-xs" style="width: 40px;"
onclick="javascript:btnPrintCNTicked_Click({$rows.id},$('#cpyCN{$rows.id}').val())">CN</button>
</span>
</td>
</tr>
</table>
<div class="table-responsive" style="margin-top: 10px;">
<table class="table table-hover table-bordered" style="font-size: 8pt;">
<thead>
<tr class="panel-default" style="height: 30px;">
<th style="width: 20px;">
<input type="checkbox" id="chkAll" style="width: 15px; height: 15px;" onchange="toggleTick_Change()" />
</th>
<th style="width: 40px;">
#
</th>
<th style="width: 140px;">
DELIVERY NO / <br>DATE / TYPE
</th>
</tr>
</thead>
<tbody>
<tr class="panel-default" style="height: 30px;">
<th style="width: 20px;">
<input type="checkbox" id="chkT" style="width: 15px; height: 15px;" onchange="toggleTick_Change()" />
</th>
<th style="width: 140px;">
abcd
</th>
</tr>
<tr class="panel-default" style="height: 30px;">
<th style="width: 20px;">
<input type="checkbox" id="chkT" style="width: 15px; height: 15px;" onchange="toggleTick_Change()" />
</th>
<th style="width: 140px;">
1234
</th>
</tr>
</tbody>
</table>
</div>
<!--/id -page content-->
</div>
<!--/id -page container-->
</div>
<!-- /container -->
</div>
<!-- /content -->
【问题讨论】:
标签: javascript html jquery