动态控件组和复选框无样式
因此,我尝试将动态内容直接加载到我的复选框容器 (group_checkboxes) 中。
<div id='group_checkboxes' data-role="fieldcontain">
</div>
这是我运行的用于填充容器的语句:
$('#group_checkboxes').append('<fieldset data-role="controlgroup"><input type="checkbox" name="' + $(this).find('data').text() + '" class="custom" /><label for="' + $(this).find('data').text() + '">' + $(this).find('label').text() + '</label></fieldset>');
复选框已全部填充,但未应用 jQuery 样式。
根据文档我需要做的所有事情要做的就是调用这个函数来更新复选框样式...
$("input[type='checkbox']").checkboxradio("refresh");
但这不起作用...知道我做错了什么吗?
So I'm trying to load dynamic content straight into my checkbox container (group_checkboxes)
<div id='group_checkboxes' data-role="fieldcontain">
</div>
This is the statement I'm running to populate the container:
$('#group_checkboxes').append('<fieldset data-role="controlgroup"><input type="checkbox" name="' + $(this).find('data').text() + '" class="custom" /><label for="' + $(this).find('data').text() + '">' + $(this).find('label').text() + '</label></fieldset>');
The checkboxes are all populated but the jQuery style is not applied.
According to the docs all I need to do is call this function to update the checkbox style...
$("input[type='checkbox']").checkboxradio("refresh");
That doesn't work though... Any idea what I'm doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
将复选框或单选按钮动态附加到 controlgroup 时,您会处理两个 jQuery Mobile 小部件:
.checkboxradio()
和.controlgroup()
。添加新元素后,两者都应该使用 jQuery Mobile CSS 创建/更新/增强/样式化。
最新稳定版本和RC版本实现的方式有所不同,但方法是相同的。
jQuery Mobile 1.2.x - 1.3.x(稳定版本)
将复选框 / 单选按钮附加到静态或动态控制组后,
.checkboxradio() 来增强 复选框 / 单选按钮 标记,然后调用
.controlgroup("refresh")
重新设置 controlgroup div 的样式。jQuery Mobile 1.4.x
这里唯一的区别是应该附加元素到
.controlgroup("container")
,然后使用
.enhanceWithin()
增强 controlgroup 及其中的所有元素。When appending checkboxes or radio buttons to a controlgroup dynamically, you deal with two jQuery Mobile widgets,
.checkboxradio()
and.controlgroup()
.Both should be created/updated/enhanced/styled with jQuery Mobile CSS once new elements are added.
The way to achieve this is different in latest stable versions and RC version, but the methods are the same.
jQuery Mobile 1.2.x - 1.3.x (stable versions)
After appending checkbox / radio button to either a static or dynamic controlgroup,
.checkboxradio()
should be called first to enhance checkbox / radio button markup and then.controlgroup("refresh")
to re-style controlgroup div.jQuery Mobile 1.4.x
The only difference here is elements should be appended to
.controlgroup("container")
and then enhance both controlgroup and all elements within it, using
.enhanceWithin()
.首先尝试他们自己的静态演示代码:
正如我在评论中提到的,他们只使用一个字段集。
如果这有效,则调整您的脚本以动态生成相同的标记,然后刷新它们。
如果这适用于他们的代码,您就会知道标记中有错误。如果不是,则该刷新函数有错误。 (我知道这不是最终的解决方案,但有时你必须进行一些调试:)
编辑:
发现类似问题,使用
Page()
解决JQM 常见问题解答
SO问题
First try their own static demo code:
They are using just one fieldset as I mentioned in comments.
If this works, then adjust your script to generate the same markup dynamically and then refresh them
If this will work with their code, you will know that you have error in markup. If not, there is an error with that refresh function. (I know it's not final solution but you have to do a bit of debugging sometimes :)
Edit:
Found similar problems, solved by using
Page()
JQM FAQ
SO Question
尝试使用
$("#").trigger("create");
http://jsfiddle.net/YKvR3/36/
try with
$("#<id of fieldset controlgroup>").trigger("create");
http://jsfiddle.net/YKvR3/36/
尝试
try
它只适合我。知道为什么吗?
我的答案是:
It works just ones for me. Any idea why?
The Answer for me is:
对我来说,解决方法是删除整个字段集,然后用我想要添加的新项目替换放置新的字段集,然后在整个页面上调用
.trigger('pagecreate');
方法。这不是最有效的解决方案,但这是唯一适用于我的情况的解决方案。What work out for me was to remove the whole fieldset then replace place a new fieldset with the new item I wanted to add then I called the
.trigger('pagecreate');
method on the whole page. This is not the most efficient solution but that is the only one that worked in my case.