我正在从数据库填充下拉列表。我正在使用jQuery/jQuery的移动。我可以填充下拉菜单。我的问题是,当它被填充时,它不显示第一个值,除非我选择其他元素,然后再次选择第一个元素。使用jquery mobile填充下拉列表
http://jsfiddle.net/hozefa/TtguK/
上面的小提琴有我目前使用的代码。
我正在从数据库填充下拉列表。我正在使用jQuery/jQuery的移动。我可以填充下拉菜单。我的问题是,当它被填充时,它不显示第一个值,除非我选择其他元素,然后再次选择第一个元素。使用jquery mobile填充下拉列表
http://jsfiddle.net/hozefa/TtguK/
上面的小提琴有我目前使用的代码。
你所面临的问题是,你需要 “刷新” <select>
部件使用.selectmenu('refresh')
:
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');
这里是一个演示:http://jsfiddle.net/TtguK/9/
可能:http://jsfiddle.net/TtguK/11/ – 2011-12-21 20:06:50