gpt4 book ai didi

javascript - 数据切换引导折叠复选框问题

转载 作者:行者123 更新时间:2023-11-28 16:50:08 27 4
gpt4 key购买 nike

我在使用的代码中遇到了一些数据切换 Bootstrap 的问题。

当我想点击复选框时,数据切换也会被触发。单击复选框时有什么方法可以防止数据切换功能?或者任何解决方案

当我想点击复选框时,数据切换也会被触发。单击复选框时有什么方法可以防止数据切换功能?或者任何解决方案

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<table>
<thead>
<tr>
<th rowspan="2" style="vertical-align: middle; text-align: center">No. Kegiatan</th>
<th rowspan="2" style="vertical-align: middle; text-align: center">Nama</th>
<th rowspan="2" style="vertical-align: middle; text-align: center">Pagu</th>
<th colspan="2" style="vertical-align: middle; text-align: center">Aksi</th>
<th rowspan="2" style="width:20%;vertical-align: middle; text-align: center">PPTK</th>
</tr>
</thead>
<tbody>
<tr id="5" data-toggle="collapse" data-target=".collapse-2">
<td style="width: 150px;">5</td>
<td>BELANJA</td>
<td>426,132,000
</td>
<td class="text-center">
<input type="checkbox" name="cpaket[]" class="checkleng cpk1" value="BELANJA">
</td>
<td class="text-center">
<input type="checkbox" name="canggaran[]" class="checkleng cang1" value="BELANJA">
</td>
<td>
<select class="form-control pkts1 akay show_only" name="pkt_pptk[]" style="display: none;">
<option value="">-- Pilih PPK --</option>
</select>
<select class="form-control anggs1 akay show_only" name="angg_pptk[]" style="display: none;">
<option value="">-- Pilih PPK --</option>
</select>
</td>
</tr>
<tr id="52" data-parent="#5" class="collapse-2 collapse in" data-toggle="collapse" data-target=".collapse-3-52" aria-expanded="true" style="">
<td style="width: 150px;">5 . 2</td>
<td>BELANJA LANGSUNG</td>
<td>426,132,000</td>
<td class="text-center">
<input type="checkbox" name="cpaket[]" class="checkleng cpk2" value="BELANJA LANGSUNG">
</td>
<td class="text-center">
<input type="checkbox" name="canggaran[]" class="checkleng cang2" value="BELANJA LANGSUNG">
</td>
<td>

<select class="form-control pkts2 akay show_only" name="pkt_pptk[]" style="display: none">
<option value="">-- Pilih PPK --</option>
</select>
<select class="form-control anggs2 akay show_only" name="angg_pptk[]" style="display: none">
<option value="">-- Pilih PPK --</option>
</select>
</td>
</tr>
<tr id="521" data-parent="#52" class="collapse-3-52 collapse in" data-toggle="collapse" data-target=".collapse-4-521" aria-expanded="true" style="">
<td style="width: 150px;">5 . 2 . 1</td>
<td>Belanja Pegawai</td>
<td>8,652,000</td>
<td class="text-center">
<input type="checkbox" name="cpaket[]" class="checkleng cpk3" value="Belanja Pegawai">
<input type="checkbox" name="d_namacpk[]" class="cpk3" value="Belanja Pegawai" style="display: none">
<input type="checkbox" name="d_pagucpk[]" class="cpk3" value="8652000" style="display: none">
</td>
<td class="text-center">
<input type="checkbox" name="canggaran[]" class="checkleng cang3" value="Belanja Pegawai">
</td>
<td> <select class="form-control pkts3 akay show_only" name="pkt_pptk[]" style="display: none">
<option value="">-- Pilih PPK --</option>
</select>
<select class="form-control anggs3 akay show_only" name="angg_pptk[]" style="display: none">
<option value="">-- Pilih PPK --</option>
</select>
</td>
</tr>
</tbody>
</table>

最佳答案

有很多方法可以做到这一点,但这里有一种停止传播的简单方法

$('input[type="checkbox"]').click(function(e){
e.stopPropagation()
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<table>
<thead>
<tr>
<th rowspan="2" style="vertical-align: middle; text-align: center">No. Kegiatan</th>
<th rowspan="2" style="vertical-align: middle; text-align: center">Nama</th>
<th rowspan="2" style="vertical-align: middle; text-align: center">Pagu</th>
<th colspan="2" style="vertical-align: middle; text-align: center">Aksi</th>
<th rowspan="2" style="width:20%;vertical-align: middle; text-align: center">PPTK</th>
</tr>
</thead>
<tbody>
<tr id="5" data-toggle="collapse" data-target=".collapse-2">
<td style="width: 150px;">5</td>
<td>BELANJA</td>
<td>426,132,000
</td>
<td class="text-center">
<input type="checkbox" name="cpaket[]" class="checkleng cpk1" value="BELANJA">
</td>
<td class="text-center">
<input type="checkbox" name="canggaran[]" class="checkleng cang1" value="BELANJA">
</td>
<td>
<select class="form-control pkts1 akay show_only" name="pkt_pptk[]" style="display: none;">
<option value="">-- Pilih PPK --</option>
</select>
<select class="form-control anggs1 akay show_only" name="angg_pptk[]" style="display: none;">
<option value="">-- Pilih PPK --</option>
</select>
</td>
</tr>
<tr id="52" data-parent="#5" class="collapse-2 collapse in" data-toggle="collapse" data-target=".collapse-3-52" aria-expanded="true" style="">
<td style="width: 150px;">5 . 2</td>
<td>BELANJA LANGSUNG</td>
<td>426,132,000</td>
<td class="text-center">
<input type="checkbox" name="cpaket[]" class="checkleng cpk2" value="BELANJA LANGSUNG">
</td>
<td class="text-center">
<input type="checkbox" name="canggaran[]" class="checkleng cang2" value="BELANJA LANGSUNG">
</td>
<td>

<select class="form-control pkts2 akay show_only" name="pkt_pptk[]" style="display: none">
<option value="">-- Pilih PPK --</option>
</select>
<select class="form-control anggs2 akay show_only" name="angg_pptk[]" style="display: none">
<option value="">-- Pilih PPK --</option>
</select>
</td>
</tr>
<tr id="521" data-parent="#52" class="collapse-3-52 collapse in" data-toggle="collapse" data-target=".collapse-4-521" aria-expanded="true" style="">
<td style="width: 150px;">5 . 2 . 1</td>
<td>Belanja Pegawai</td>
<td>8,652,000</td>
<td class="text-center">
<input type="checkbox" name="cpaket[]" class="checkleng cpk3" value="Belanja Pegawai">
<input type="checkbox" name="d_namacpk[]" class="cpk3" value="Belanja Pegawai" style="display: none">
<input type="checkbox" name="d_pagucpk[]" class="cpk3" value="8652000" style="display: none">
</td>
<td class="text-center">
<input type="checkbox" name="canggaran[]" class="checkleng cang3" value="Belanja Pegawai">
</td>
<td> <select class="form-control pkts3 akay show_only" name="pkt_pptk[]" style="display: none">
<option value="">-- Pilih PPK --</option>
</select>
<select class="form-control anggs3 akay show_only" name="angg_pptk[]" style="display: none">
<option value="">-- Pilih PPK --</option>
</select>
</td>
</tr>
</tbody>
</table>

关于javascript - 数据切换引导折叠复选框问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59352383/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com