簡體   English   中英

如果我選擇第一個復選框,則禁用所有剩余的復選框

[英]If I select first checkbox then disable all remaining checkboxes

我在單獨的標簽中有四個復選框。

如果我選擇第一個復選框,則所有其余復選框將被禁用。 如果再次單擊第一個 ,將啟用所有復選框。 如果我選擇任何其他復選框,則其他復選框仍處於啟用狀態:我可以選擇多個復選框。 在這里查看圖片

我該如何設置?

如果要詢問如何禁用所有其他“復選框”,請使用無線電組。 如果您說第一個復選框會自動觸發其他復選框的切換,請嘗試將它們取消分組,或者將它們彼此分開,因為這聽起來好像您在這里存在某種錯誤的分組和依賴性。

嘗試這個:

HTML:

<label for="one"><input type="checkbox" name="one" id="one"></label>
<label for="two"><input type="checkbox" name="two" id="two"></label>
<label for="three"><input type="checkbox" name="three" id="three"></label>
<label for="four"><input type="checkbox" name="four" id="four"></label>

jQuery的:

$('input[type="checkbox"]').on('change', function() {
    if($('input[type="checkbox"]').eq(0).is(':checked')){
        $('input[type="checkbox"]').not($(this)).attr('disabled', true);
    }
    else{
        $('input[type="checkbox"]').not($(this)).attr('disabled', false);
    }
});

工作示例: https//jsfiddle.net/e26vnnk2/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM