如果使用Bootstrap Select更改其他选择,则移除选定属性

dgenwo3n  于 2022-12-16  发布在  Bootstrap
关注(0)|答案(1)|浏览(138)

如果兄弟select更改了option,我想从select中删除selected属性。对于普通的jQuery,这段代码可以正常工作。https://jsfiddle.net/hv0x43em/1/
但是,我也使用Bootstrap Select
使用Bootstrap Select时,selected属性似乎没有被删除。下面是我的小提琴和代码:https://jsfiddle.net/L71xtwx3/2/

$(document).ready(function() {
  $(".charts-city").on('change', function(e) {
    var dataOptions = $(this).closest(".form-group").next().find(".charts-data option");
    $(dataOptions).prop("selected", false);
    e.preventDefault();
  });
});

你知道怎么做吗?

sgtfey8w

sgtfey8w1#

根据你的jsfidle演示代码,你拿错了类图表-provinsi而不是图表-city。
以下是工作代码

$(document).ready(function() {
    $(".charts-city").on('change', function(e) {
        $(".charts-data").val('0');
        $(".charts-data").selectpicker("refresh");
    });
});

这里是推荐链接https://silviomoreto.github.io/bootstrap-select/methods/#selectpickerrefresh
这是https://jsfiddle.net/L71xtwx3/6/的工作演示

相关问题