jquery-mobile 创建动态控制组并应用 jquery-ui css

标签 jquery-mobile fieldset dynamic-html

这个问题在这里已经有了答案:





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();});​

enter image description here
我做错了什么?
谢谢。

最佳答案

$("#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/

相关文章:

css - 在 jQuery Mobile 中设置 Listview <li> 高度

javascript - 删除最后一个追加

javascript - 设置秒表定时器的格式

css - 当我在里面有一个字段集时,div 高度不会扩展

css - 如何固定字段集宽度

jquery - 如何更改动态添加元素的CSS?

JQuery 代码不运行

html - 使用 CSS 使 <fieldset> 适合其内容的大小?

c# - 如何使用 .NET 的 WebBrowser 或 mshtml.HTMLDocument 动态生成 HTML 代码?

javascript - 我正在尝试使用 Javascript 读取示例 json 动态插入一段 html 代码,但无法这样做