set option “selected” attribute from dynamic created option

后端 未结 17 1704
时光说笑
时光说笑 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:45

    Realize this is an old question, but with the newer version of JQuery you can now do the following:

    $("option[val=ID]").prop("selected",true);
    

    This accomplishes the same thing as Box9's selected answer in one line.

提交回复
热议问题