set option “selected” attribute from dynamic created option

后端 未结 17 1738
时光说笑
时光说笑 2020-11-30 20:01

I have a dynamically created select option using a javascript function. the select object is


<         


        
17条回答
  •  感情败类
    2020-11-30 20:38

    What you want to do is set the selectedIndex attribute of the select box.

    country.options.selectedIndex = index_of_indonesia;
    

    Changing the 'selected' attribute will generally not work in IE. If you really want the behavior you're describing, I suggest you write a custom javascript reset function to reset all the other values in the form to their default.

提交回复
热议问题