javascript - jquery mobile - 附加 html 内容并应用 JQuery mobile 的样式

标签 javascript jquery xml ajax jquery-mobile

我有一个移动网站,它是通过附加 XML 提要中的数据创建的。最初加载提要及其所有数据,然后在用户浏览站点时从数组中获取适当的提要内容。以前的内容从 div 中清除,并应用新内容。我试图在附加新内容后调用某种 update() 函数到 jquery mobile 以便它更新哈希、应用适当的类等,但我似乎无法在文档中找到它.我在这里阅读这篇文章:

Dynamically creating jQuery Mobile pages using jQuery Templates

但是我找不到任何地方记录的 page() 函数,它似乎对我不起作用。有什么想法可以实现吗?

最佳答案

看看 latest documentation and demos page

Enhancing new markup The page plugin dispatches a “pagecreate” event, which most widgets use to auto-initialize themselves. As long as a widget plugin script is referenced, it will automatically enhance any instances of the widgets it finds on the page.

However, if you generate new markup client-side or load in content via Ajax and inject it into a page, you can trigger the create event to handle the auto-initialization for all the plugins contained within the new markup. This can be triggered on any element (even the page div itself), saving you the task of manually initializing each plugin (listview button, select, etc.).

For example, if a block of HTML markup (say a login form) was loaded in through Ajax, trigger the create event to automatically transform all the widgets it contains (inputs and buttons in this case) into the enhanced versions. The code for this scenario would be:

$( ...new markup that contains widgets... ).appendTo( ".ui-page").trigger( "create" );

关于javascript - jquery mobile - 附加 html 内容并应用 JQuery mobile 的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7069508/

相关文章:

将我的 asp.net.core 2.0 应用程序发布到 IIS 时 JavaScript 未运行

javascript - 跨源资源共享 (CORS) 是否区分 HTTP 和 HTTPS?

javascript - jQuery/JavaScript : Event handlers only assigned during the last iteration of a loop

jquery - IE 11 中的 FormData 未定义

javascript - 创建唯一变量

xml - XSLT 新行插入不能按预期与 Hive 一起工作

java - 解析 XML 时检索它们

javascript - filter(cond) 和 flatMap(x => cond 之间有区别吗? of(x) : EMPTY)?

javascript - 计算数组的百分比

css - 通过 CSS 对列表进行编号,仅当有多个元素时