Change value of materialize select box by jquery

前端 未结 11 1533
滥情空心
滥情空心 2020-12-29 22:18

I want to change materialize select box value by jquery.

I am using $(\'#myselect\').val(\'1\'); on onchange event of other select box but

11条回答
  •  旧时难觅i
    2020-12-29 22:53

    In 2018 (Materialize v1.0.0-rc.2), first you have to set your option programmatically:

    $('#SELECT-ID').find('option[value="SELECT-VALUE"]').prop('selected', true);
    

    And then re-initialise the select input with:

    $("#SELECT-ID").formSelect();
    

    Hope it helps!

提交回复
热议问题