我试图动态创建一个select
元素,但它不是由jQuery Mobile设计的。实现这一目标的正确方法是什么?
这是一个有效的jsFiddle
例子:http://jsfiddle.net/Gajotres/dEXac/
$(document).on('pagebeforeshow', '#index', function(){
// Add a new select element
$('<select>').attr({'name':'select-choice-1','id':'select-choice-1'}).appendTo('[data-role="content"]');
$('<option>').attr({'value':'1'}).html('Value 1').appendTo('#select-choice-1');
$('<option>').attr({'value':'2'}).html('Value 2').appendTo('#select-choice-1');
// Enhance new select element
$('select').selectmenu();
});
值得注意的是,这也应该有效:(示例附加两个选项以显示如何添加选项。
$('<select name="sl" id="sl" data-native-menu="false"><option value="clear">That I got</option></select>').appendTo("#output");
$('<option value="clear2">Another That I got</option>').appendTo("#sl");
$('select').selectmenu();
这个对我有用
$(document).on('change', "body", function(){
$( ".ui-selectmenu" ).selectmenu();
});