set option “selected” attribute from dynamic created option

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

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


<         


        
17条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 20:44

    Instead of modifying the HTML itself, you should just set the value you want from the relative option element:

    $(function() {
        $("#country").val("ID");
    });
    

    In this case "ID" is the value of the option "Indonesia"

提交回复
热议问题