jQuery - setting the selected value of a select control via its text description

前端 未结 22 1315
夕颜
夕颜 2020-11-22 09:16

I have a select control, and in a javascript variable I have a text string.

Using jQuery I want to set the selected element of the select control to be the item with

22条回答
  •  野性不改
    2020-11-22 09:52

    Just on a side note. My selected value was not being set. And i had search all over the net. Actually i had to select a value after a call back from a web service, because i was getting data from it.

    $("#SelectMonth option[value=" + DataFromWebService + "]").attr('selected', 'selected'); 
    $("#SelectMonth").selectmenu('refresh', true);
    

    So the refresh of the selector was was the only thing that i was missing.

提交回复
热议问题