jQuery Mobile 动态添加元素
我正在尝试添加 列表视图< /a> 加载 jQuery 移动网站后。仅仅将其添加到 DOM 中是行不通的,因为加载后它不会解析数据角色标签。这是一个示例: http://jsfiddle.net/Xeon06/h2gfT/2/
我的问题是,如何刷新呢?我发现了许多类似的问题,其答案范围从使用 .refresh (这不起作用,因为该元素从未初始化为列表视图)到 .page (根本不起作用,我不知道为什么)。在撰写本文时,我正在使用最新版本的 jQuery mobile,1.02b。
谢谢。
I am trying to add a list view to a jQuery mobile site after the site has been loaded. Merely adding it to the DOM doesn't work because it doesn't parse it for data-role tags once it has been loaded. Here is an example: http://jsfiddle.net/Xeon06/h2gfT/2/
My question is, how do I refresh it? I've found numerous similar questions with answers ranging from using .refresh (which doesn't work because the element is never initialized as a list view) to .page (which doesn't work at all and I have no idea why). I am using the latest version of jQuery mobile at the time of writing, 1.02b.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在元素上调用
.listview()
。更新了小提琴
You can call
.listview()
on your element.Updated fiddle
我刚刚从页面中删除了
data-role
属性以使其正常工作。我认为这是您标记中的问题。http://jsfiddle.net/h2gfT/3/
I just removed the
data-role
attribute from page to make it work. I think that was the issue in your markup.http://jsfiddle.net/h2gfT/3/
我喜欢调用 jQuery 触发器方法来完成此操作:
$(element).trigger("create")
到目前为止,它对我来说没有任何问题,尽管我听说它创建新页面这可能会产生问题。
I like to call the jQuery trigger method to accomplish this:
$(element).trigger("create")
So far it works for me without a hitch although I have heard it reported that creating new pages with this can be problematic.