我希望能夠使用 Jquery Javascript 僅選中 4 個復選框中的一個復選框,我在 PHP 生成的同一頁面中有多個帶有 4 個復選框的表單,我的方法是
<script>
$('input.chk1').on('change', function() {
$('input.chk1').not(this).prop('checked', false);
});
$('input.chk2').on('change', function() {
$('input.chk2').not(this).prop('checked', false);
});
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<form action="">
<input type="checkbox" id="chk1" class="chk1"/>
<input type="checkbox" id="chk2" class="chk1"/>
<input type="checkbox" id="chk3" class="chk1"/>
<input type="checkbox" id="chk4" class="chk1"/>
</form>
<form action="">
<input type="checkbox" id="chk1" class="chk2"/>
<input type="checkbox" id="chk2" class="chk2"/>
<input type="checkbox" id="chk3" class="chk2"/>
<input type="checkbox" id="chk4" class="chk2"/>
</form>
......
什么是最好的方法來實作這一點,因為我在一個專案串列中有這么多表格?
uj5u.com熱心網友回復:
我設法使用單選按鈕而不是復選框
這個解決方案也解決了我的問題: html select only one checkbox in a group
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/430907.html
