这个问题在这里已经有了答案:
Dynamic controlgroup and checkboxes unstyled
(6 个回答)
7年前关闭。
这是我的代码:
http://jsfiddle.net/YKvR3/34/
我将使用数组(名称)中的值创建一个控制组。
问题是,当我单击加载按钮时,值会添加到控制组中,但 jquery-ui 样式并未像图像中那样加载。
控制组没有使用 jquery-ui mobile css 设置样式。
$("#load").click(function(){
var name=["one","two"];
var html='<fieldset id="listPlayers" data-role="controlgroup"><legend><h1>Choose as many players as youd like to remove:</h1></legend>';
for ( var int = 0; int < 2; int++) {
html+='<input type="checkbox" name="checkbox-'+int+'a" id="checkbox-'+int+'a" class="custom" /><label for="checkbox-'+int+'a">'+name[int]+'</label>';
}
alert('<legend><h3>Choose as many players as you would like to remove:</h3></legend>'+html+'</fieldset');
$("#list").html(html+'</fieldset');
//$("#list").page();});
我做错了什么?
谢谢。
最佳答案
$("#list").trigger('create');
发件人:jqm docs
if you generate new markup client-side or load in content via Ajax and inject it into a page, you can trigger the create event to handle the auto-initialization for all the plugins contained within the new markup. This can be triggered on any element (even the page div itself), saving you the task of manually initializing each plugin (listview button, select, etc.).
关于jquery-mobile 创建动态控制组并应用 jquery-ui css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13587333/