HTML checkbox - allow to check only one checkbox

前端 未结 5 1888
花落未央
花落未央 2021-01-19 14:07

I have some checkboxes in each row in my table. Each one checkbox has name=\'myName\' because I want to select only one checkbox in each row. But something I\'m

相关标签:
5条回答
  • 2021-01-19 14:10
    sapSet = mbo.getThisMboSet()
    sapCount = sapSet.count()
    saplist = []
    
    if sapCount > 1:
       for i in range(sapCount):`enter code here`
         defaultCheck = sapSet.getMbo(i)
         saplist.append(defaultCheck.getInt("HNADEFACC"))
       defCount = saplist.count(1)
       if defCount > 1:
          errorgroup = " Please Note: you are allowed"
          errorkey = "  only One Default Account"
       if defCount < 1:
          errorgroup = " Please enter "
          errorkey = "  at leat One Default Account"
    else:
       mbo.setValue("HNADEFACC",1,MboConstants.NOACCESSCHECK)
    
    0 讨论(0)
  • 2021-01-19 14:12
     $(function () {
         $('input[type=checkbox]').click(function () {
             var chks = document.getElementById('<%= chkRoleInTransaction.ClientID %>').getElementsByTagName('INPUT');
             for (i = 0; i < chks.length; i++) {
                chks[i].checked = false;
             }
             if (chks.length > 1)
                $(this)[0].checked = true;
         });
     });
    
    0 讨论(0)
  • 2021-01-19 14:15

    Checkboxes, by design, are meant to be toggled on or off. They are not dependent on other checkboxes, so you can turn as many on and off as you wish.

    Radio buttons, however, are designed to only allow one element of a group to be selected at any time.

    References:

    Checkboxes: MDN Link

    Radio Buttons: MDN Link

    0 讨论(0)
  • 2021-01-19 14:23

    The unique name identifier applies to radio buttons:

    <input type="radio" />
    

    change your checkboxes to radio and everything should be working

    0 讨论(0)
  • 2021-01-19 14:29
    $('#OvernightOnshore').click(function () {
        if ($('#OvernightOnshore').prop("checked") == true) {
            if ($('#OvernightOffshore').prop("checked") == true) {
                $('#OvernightOffshore').attr('checked', false)
            }
        }
    })
    
    $('#OvernightOffshore').click(function () {
        if ($('#OvernightOffshore').prop("checked") == true) {
            if ($('#OvernightOnshore').prop("checked") == true) {
                $('#OvernightOnshore').attr('checked', false);
            }
        }
    })
    

    This above code snippet will allow you to use checkboxes over radio buttons, but have the same functionality of radio buttons where you can only have one selected.

    0 讨论(0)
提交回复
热议问题