admin管理员组文章数量:1429494
I have the following jQuery Mobile HTML code, the navbar's content is set using javascript. jQuery mobile styles the navbar when it's set statically, but when you set the content of it (html) later using javascript, you have to do some extra work to make it work:
<div data-role="header">
<h1 id="title">App</h1>
</div><!-- /header -->
<div data-role="content" id="content">
<p>Loading...</p>
</div><!-- /content -->
<div data-role="footer" data-position="fixed">
<div data-role="navbar" id="navbar">
<ul id="menu">
</ul>
</div>
</div><!-- /footer -->
</div><!-- /page -->
trigger('create');
is generally used to solve the problem of unstyled markup when set using javascript/ajax. However, it seems only to work within data-role="content"
and not for #navbar
. The script below should work but leaves the menu unstyled...
$(function(){
$("#menu").html("<li><a href='#'>Test Styling</a></li>").trigger('create');
});
Any ideas how to solve this? I have tried page();
and .listview('refresh');
with no results.
I have the following jQuery Mobile HTML code, the navbar's content is set using javascript. jQuery mobile styles the navbar when it's set statically, but when you set the content of it (html) later using javascript, you have to do some extra work to make it work:
<div data-role="header">
<h1 id="title">App</h1>
</div><!-- /header -->
<div data-role="content" id="content">
<p>Loading...</p>
</div><!-- /content -->
<div data-role="footer" data-position="fixed">
<div data-role="navbar" id="navbar">
<ul id="menu">
</ul>
</div>
</div><!-- /footer -->
</div><!-- /page -->
trigger('create');
is generally used to solve the problem of unstyled markup when set using javascript/ajax. However, it seems only to work within data-role="content"
and not for #navbar
. The script below should work but leaves the menu unstyled...
$(function(){
$("#menu").html("<li><a href='#'>Test Styling</a></li>").trigger('create');
});
Any ideas how to solve this? I have tried page();
and .listview('refresh');
with no results.
1 Answer
Reset to default 4Try calling the navbar
method after appending the list item:
$(function(){
$("#menu").html("<li><a href='#'>Test Styling</a></li>");
$("#navbar").navbar();
});
Edit: You could also try creating the navbar dynamically :
var footer = $("#footer-id");
var navBar = $("div", {
"data-role":"navbar",
"html":"<ul><li><a href='#'>Test Styling</a></li></ul>"
}).appendTo(footer).navbar();
版权声明:本文标题:javascript - jQuery Mobile: alternative of .trigger('create') or .page() when updating navbar? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745506458a2661268.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论