动态更改jQuery Mobile选择框的选择值

时间:2015-05-19 07:39:49

标签: jquery-mobile

我已动态创建了选择菜单。如何将所选值动态更改为第三个值(Apple)。

HTML

table.WriteSelectedRows (0, -1, pageSize.GetLeft (25), pageSize.GetTop (10), cb);

代码

<div>
    <select id="stylex" data-mini="true">   </select>
</div>

JSFiddle

1 个答案:

答案 0 :(得分:0)

更新了您的JS小提琴:http://jsfiddle.net/rhLt2sxj/5/

var wid_settings = ["Banana", "Orange", "Apple", "Mango"];

wid_settings_refresh();

function wid_settings_refresh() {
    var index;
    for (index = 0; index < wid_settings.length; index++) {

        $('#stylex').append('<option value=' + index + '>' + wid_settings[index] + '</option>');
    }
    $('#stylex').val(3);
    //$('#stylex').listview('refresh'); //not necessary
}