使用jquery mobile填充下拉列表

使用jquery mobile填充下拉列表,jquery,html,jquery-mobile,Jquery,Html,Jquery Mobile,我正在从数据库填充下拉列表。我正在使用jquery/jquerymobile。我可以填充下拉列表。我的问题是,当它被填充时,它不会显示第一个值,除非我选择其他元素,然后再次选择第一个元素 上面的提琴有我当前使用的代码。您面临的问题是需要使用刷新小部件。选择菜单“刷新”: 这里有一个演示:@Hozefa不客气。如果您只需要从中获取一条信息,请记住每个jQuery Mobile小部件都有类似的内容,它们都可以通过编程方式创建/刷新。可能: var temp = ['5.00', '10.00', '

我正在从数据库填充下拉列表。我正在使用jquery/jquerymobile。我可以填充下拉列表。我的问题是,当它被填充时,它不会显示第一个值,除非我选择其他元素,然后再次选择第一个元素


上面的提琴有我当前使用的代码。

您面临的问题是需要使用刷新小部件。选择菜单“刷新”:


这里有一个演示:

@Hozefa不客气。如果您只需要从中获取一条信息,请记住每个jQuery Mobile小部件都有类似的内容,它们都可以通过编程方式创建/刷新。可能:
var temp = ['5.00', '10.00', '15.00', '25.00', '50.00', '100.00'],
    output = [];

//notice I cached the `temp.length` value, the `for` loop will perform faster if this is done
for(var i = 0, len = temp.length; i < len; i++){

    //instead of appending each `<option>` element, it is a better practice to either concoct a string of all the HTML or create an array that will later be turned into a string (here we are pushing new indexes onto an `output` array)
    output.push('<option value="' + temp[i]+'">' + temp[i] + '</option>');
}

//now make a single `.append()` call with all the HTML in one big string
//and most importantly, call `.selectmenu("refresh")` after we update the HTML of the select menu so the jQuery Mobile framework will update the widget
$('#amountsList').append(output.join('')).selectmenu('refresh');