CheckboxGroup作为Radiogroup

时间:2019-05-16 17:36:33

标签: javascript

我创建具有多个类别的动态多个复选框作为标识

...
input = this._createCheckboxElement(chb_class,checked);
...
<input class="leaflet-control-layers-selector chb_01" type="checkbox">
<input class="leaflet-control-layers-selector chb_02" type="checkbox">
<input class="leaflet-control-layers-selector " type="checkbox">
<input class="leaflet-control-layers-selector " type="checkbox">
<input class="leaflet-control-layers-selector " type="checkbox">
<input class="leaflet-control-layers-selector chb_02" type="checkbox">
<input class="leaflet-control-layers-selector chb_02" type="checkbox">
...

我将使用此代码将Checkboxgroup设置为Radiogroup

// CheckboxGroup as Radiogroup
$("input[type=checkbox]").click(function() {
var this_class = ($(this).attr('class'));
if(this_class.indexOf(' ') > 0) {
    var lastWord = this_class.substr(this_class.lastIndexOf(" ") + 1);  // ='chb_xxxxxx'
    //console.log (lastWord);
    // andere checkbox mit gleicher class deaktivieren und diese aktivieren
    $("."+lastWord).prop('checked', false);// uncheck other Checkbox from this Group
    $(this).prop('checked', true);// chek this Checkbox of this Group
}
});

此操作不正确-我需要帮助

0 个答案:

没有答案