set option “selected” attribute from dynamic created option

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

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


<         


        
17条回答
  •  再見小時候
    2020-11-30 21:03

    I was trying something like this using the $(...).val() function, but the function did not exist. It turns out that you can manually set the value the same way you do it for an :

    // Set value to Indonesia ("ID"):
    $('#country').value = 'ID'
    

    ...and it get's automatically updated in the select. Works on Firefox at least; you might want to try it out in the others.

提交回复
热议问题