Select dropdown menu option with javascript

前端 未结 2 1290
长发绾君心
长发绾君心 2021-02-05 02:30

I have a dropdown menu and I cannot figure out how to make a javascript function select a drop down menu option. I have tested the output of the variables and they are all corre

2条回答
  •  鱼传尺愫
    2021-02-05 03:12

    Alt. you can set selected to the actual option: select.options[i].selected = true;

    ...
            var select = document.getElementById("stateSelect");
            for(var i = 0;i < select.options.length;i++){
                if(select.options[i].value == c ){
                    select.options[i].selected = true;
                }
            }
    ...
    

提交回复
热议问题