为什么元素载入$。阿贾克斯()没有表现出jQuery Mobile的CSS?表现出、元素、阿贾克斯、CSS

2023-09-10 19:21:19 作者:恶魔尊主

我在jQuery Mobile的做了一个网站。我装通过jQuery的 $一些HTML内容。阿贾克斯()的功能。

I made a website in jQuery Mobile. I loaded some HTML content via the jQuery $.ajax() function.

在code加载包含这样的功能按钮和扩展,能够部分。

The code loaded contains such features as buttons and expand-able sections.

然而,没有加载的元素表现出的移动功能。在jQuery Mobile的CSS不被适用于他们。

However, none of the loaded elements exhibit mobile features. The jQuery Mobile CSS is not being applied to them.

这是否有什么关系的jQuery如何移动已经在使用Ajax来浏览周围的网页?这是不是动态加载HTML内容确实保留了jQuery Mobile的样式。

Does this have to do with how jQuery Mobile is already using Ajax to navigate around pages? The HTML content that was not loaded dynamically does retain the jQuery Mobile styles.

推荐答案

您需要刷新JQM控制的新元素:

You need to refresh jQM controls for the new elements:

http://jquerymobile.com/demos/1.0.1/docs/pages/page-scripting.html

加强新的标记 该网页插件调度pagecreate事件,其中大部分部件采用自动初始化自己。只要   作为一个小窗口插件脚本被引用时,它会自动提升   该窗口小部件的任何情况下,它找到的页面上。

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.

不过,如果您通过生成新标记的客户端或负载的内容   Ajax和注入到一个页面上,你可以触发创建事件   办理自动初始化包含在所有的插件   新的标记。这可以任何元素(甚至在网页触发   DIV本身),为您节省了手动初始化每个插件任务   (列表视图按钮,选择,等等)。

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.).

例如,如果HTML标记块(比如登录表单)装   通过阿贾克斯,触发创建事件来自动变换   所有的部件包含(输入和按钮在这种情况下)进   增强版本。在code为这种情况将是:

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" );

创建与刷新:一个重要的区别 注意,还有就是创建事件和刷新方法之间的一个重要区别   有些小部件有。在创建活动适合于提高生   标记包含一个或一个以上小窗口。刷新方法应该是   对已被操纵现有的(已增强)部件使用   编程方式,需要用户界面的更新匹配。

Create vs. refresh: An important distinction Note that there is an important difference between the create event and refresh method that some widgets have. The create event is suited for enhancing raw markup that contains one or more widgets. The refresh method should be used on existing (already enhanced) widgets that have been manipulated programmatically and need the UI be updated to match.

例如,如果你有一个页面,你动态地追加新   无序列表,数据角色=页面创建后列表视图属性,   触发创建列表的父元素将它改造   成列表视图风格小部件。如果多个列表项当时   编程方式添加,调用列表视图的刷新方法会   更新只是那些新的列表项,以增强国家和离开   现有的列表项保持不变。

For example, if you had a page where you dynamically appended a new unordered list with data-role=listview attribute after page creation, triggering create on a parent element of that list would transform it into a listview styled widget. If more list items were then programmatically added, calling the listview’s refresh method would update just those new list items to the enhanced state and leave the existing list items untouched.