渲染发生后以编程方式应用 jquery(移动)CSS 类
jquery mobile 将根据数据自动为页面上的元素应用 css 和一些 html页面加载时属性就在它们上面。
我通过 ajax 调用拉入一些 html 内容,但它是在 jquery mobile js 渲染发生后引入到页面的,因此无法获取许多 css 类。
是否可以只调用 js 并要求将渲染应用于我的新 html 内容?
之前
<div id="someDiv">
<ul data-role="listview" data-theme="b" data-inset="true">
<li>
<a href="#">
<h3>
Some title
</h3>
<p>
Some text
</p>
</a>
</li>
</ul>
</div>
之后
<div id="someDiv">
<ul data-role="listview" data-theme="b" data-inset="true" class="ui-listview ui-listview-inset ui-corner-all ui-shadow">
<li data-theme="b" class="ui-btn ui-btn-icon-right ui-li ui-corner-top ui-corner-bottom ui-btn-up-b">
<div class="ui-btn-inner ui-li ui-corner-top ui-corner-bottom">
<div class="ui-btn-text">
<a href="#" class="ui-link-inherit">
<h3 class="ui-li-heading">
Some title
</h3>
<p class="ui-li-desc">
Some text
</p>
</a>
</div>
<span class="ui-icon ui-icon-arrow-r"></span>
</div>
</li>
</ul>
</div>
jquery mobile will automatically apply css and some html for elements on the page based on what data- attributes are on them when the page loads.
I am pulling in some html content via an ajax call but it is introduced to the page after the jquery mobile js rendering has occurred, and therefore does not get the many css classes.
Is it possible to just call out to the js and ask for the rendering to get applied to just my new html content?
BEFORE
<div id="someDiv">
<ul data-role="listview" data-theme="b" data-inset="true">
<li>
<a href="#">
<h3>
Some title
</h3>
<p>
Some text
</p>
</a>
</li>
</ul>
</div>
AFTER
<div id="someDiv">
<ul data-role="listview" data-theme="b" data-inset="true" class="ui-listview ui-listview-inset ui-corner-all ui-shadow">
<li data-theme="b" class="ui-btn ui-btn-icon-right ui-li ui-corner-top ui-corner-bottom ui-btn-up-b">
<div class="ui-btn-inner ui-li ui-corner-top ui-corner-bottom">
<div class="ui-btn-text">
<a href="#" class="ui-link-inherit">
<h3 class="ui-li-heading">
Some title
</h3>
<p class="ui-li-desc">
Some text
</p>
</a>
</div>
<span class="ui-icon ui-icon-arrow-r"></span>
</div>
</li>
</ul>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将
.page()
链接到您的 AJAX 调用示例:
HTML
Chain the
.page()
to your AJAX callExample:
HTML
查看 jquery.mobile-1.0a4.1.js 并阅读 this 后很棒的文章解释了小部件的用法,答案很简单:
有一个现有的 mobile.listview 小部件,它将渲染应用于列表视图。
直接将其应用到 html 中。 定位 ul 非常重要。
这是完整的例子
After looking through jquery.mobile-1.0a4.1.js and reading this great article explaining widget usage the answer was simple:
There is an existing mobile.listview widget which applies the rendering to listviews.
Apply this to the html directly. It is important to target the ul.
Here is the full example
.live() (http://api.jquery.com/live/) 事件绑定器可能就是您正在寻找的。
The .live() (http://api.jquery.com/live/) event binder might be what you're looking for.