JQuery Mobile 不刷新按钮样式
当我尝试使用如下代码在 JQuery 中创建元素时:
$('#grid').append('<div id="gridElement'+counter+'" class="ui-block-'+rowLetter(counter)+'"></div>');
$('#gridElement'+counter).append('<div id="gridContent'+counter+'" data-inline="true"></div>');
$('#gridContent'+counter).append('<a id="button'+counter+'" href="#" data-role="button"></a>');
$('#button'+counter).html('someButtonText');
元素已正确添加,但未执行 JQuery Mobile 样式。这是有道理的,我知道库在加载后立即对 DOM 执行一些操作,但我无法找到一种方法来根据命令实现此操作。显然,我需要指示 JQuery Mobile 库重建页面,但就我而言,我一般找不到任何可以执行此操作的东西。我设法找到了几篇关于选择框和列表问题的帖子,但页面上一般没有任何内容、网格或按钮。现在这可能吗?它仍处于 alpha 阶段,所以可能不是。
When I try to make an element in JQuery with code like the following:
$('#grid').append('<div id="gridElement'+counter+'" class="ui-block-'+rowLetter(counter)+'"></div>');
$('#gridElement'+counter).append('<div id="gridContent'+counter+'" data-inline="true"></div>');
$('#gridContent'+counter).append('<a id="button'+counter+'" href="#" data-role="button"></a>');
$('#button'+counter).html('someButtonText');
The elements are added properly, but the JQuery Mobile stylings are not performed. This sort of makes sense, I know that the library does a few things to the DOM as soon as it loads, but I can't figure out a way to make this happen on command. Obviously I need to instruct the JQuery Mobile library to rebuild the page, but for the life of me, I can't find anything to do this in general. I have managed to find several posts about this being a problem with select boxes and lists, but there is nothing for the page in general, grids, or buttons. Is this even possible as of now? Its still in alpha, so it may not be.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以这样做,而不是刷新整个
div
页面:data-role=collapsible
,请使用collapsible()
函数data-role=button
,请使用button()
函数示例:
Instead of refreshing the whole
div
page you can do this:data-role=collapsible
use thecollapsible()
functiondata-role=button
use thebutton()
functionExamples:
这是在我的情况下有效的方法:
我有一个包含不同元素的列表视图,每个元素都有一个 data-role="controlgroup" ,其中带有分割按钮:
在动态添加另一个列表元素(包括新的分割按钮)之后使用javascript,我需要刷新列表、控件组和按钮,如下所示:
希望对您也有帮助。
Here is what worked in my case:
I hava a listview with different elements, each of it has a data-role="controlgroup" with split-buttons in it:
After I've added another list element (including new split buttons) dynamically with javascript, I need to refresh the list, the controlgroup and the buttons like this:
Hope that helps you too.
如果您尝试刷新控制组,我想补充一点。这对我有用。
I want to add to that if you are trying to refresh a control group. This worked for me.