我正在尝试动态创建一个select
元素,但它不是由jQuery Mobile设计的。实现这一目标的正确方法是什么?
答案 0 :(得分:8)
这是一个有用的 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();
});
答案 1 :(得分:0)
值得注意的是,这也应该有效:(示例附加两个选项以显示如何添加选项。
$('<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();
答案 2 :(得分:0)
这个对我有用
src\\s*=\\s*([\"'])?([^\"']*)