Resetting Select2 value in dropdown with reset button

前端 未结 16 1170
别跟我提以往
别跟我提以往 2020-12-23 13:00

What would be the best way to reset the selected item to default? I\'m using Select2 library and when using a normal button type=\"reset\", the value i

16条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-23 13:49

    Sometimes I want to reset Select2 but I can't without change() method. So my solution is :

    function resetSelect2Wrapper(el, value){
        $(el).val(value);
        $(el).select2({
            minimumResultsForSearch: -1,
            language: "fr"
        });
    }
    

    Using :

    resetSelect2Wrapper("#mySelectId", "myValue");
    

提交回复
热议问题