我希望能夠使用 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/qita/316751.html
上一篇:掉到盒子外面的物品
