making checkboxes behave like radio buttons

后端 未结 2 1222
深忆病人
深忆病人 2021-01-16 04:05

Please see this: http://gisdev.clemson.edu/fireflies

Toward the top right are three checkboxes and I am trying to make them work like radio buttons. Part of the prog

2条回答
  •  孤城傲影
    2021-01-16 04:27

    If you want checkboxes to act as radio buttons, attach onClick event listeners to all checkboxes, remove "checked" attributes and place it on the one being clicked.

    checkboxes_controls = jQuery(document.querySelectorAll('.leaflet-control-layers-overlays input[type=checkbox]'))
    
    jQuery(checkboxes_controls).click(function(){
        jQuery(checkboxes_controls).removeAttr('checked');
        jQuery(this).attr('checked', 'checked');
    });
    

提交回复
热议问题