Change value of materialize select box by jquery

前端 未结 11 1518
滥情空心
滥情空心 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条回答
  •  长发绾君心
    2020-12-29 22:56

    It appears to work fine for me, changing the first drop down, resets the value of the second drop down to 1.

    I have done a rough implementation on jsFiddle: http://jsfiddle.net/55r8fgxy/1/

    
    
    
    

    JS:

    $(function() {
        $("#select1").on('change', function() {
            $('#myselect').val("1");
    
            // re-initialize material-select
            $('#myselect').material_select();
        });
    });
    

提交回复
热议问题