使用jQuery Mobile刷新表单页面 [英] refresh form page with jQuery Mobile

查看:108
本文介绍了使用jQuery Mobile刷新表单页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的移动网站中,我使用javascript动态创建了一个表单,因此我需要重新加载"页面才能获得jQuery Mobile样式. 对于列表视图,我们可以简单地调用$(#mylistview").listview("refresh"),但表单没有这种功能.

In my mobile website, I dynamically create a form in javascript, so I need the 'reload' the page to get the jQuery Mobile style. For a listview, we can simply call $("#mylistview").listview("refresh") but there is no such feature for form.

我知道我们可以在表单的每个元素上调用刷新",但是这样做不能正确地应用样式.确实,我所有的复选框都分开了,它们没有出现在一个插图"中

I know that we can call "refresh" one each element of the form, but by doing this, the style is not correctly applied. Indeed, all my checkbox get separated, they don't appears in one "inset"

我有什么解决方法吗?

推荐答案

发行说明中的​​文档:

Docs in the release notes:

示例:

$('#nameOfPage').trigger('create');

报价:

新的创建"事件:一次轻松增强所有小部件

虽然页面插件不再专门调用每个插件,但是它 确实调度了"pagecreate"事件,大多数小部件都使用该事件来 自动初始化自己.只要一个小部件插件脚本是 引用后,它将自动增强小部件的任何实例 就像以前一样,它可以在页面上找到.例如,如果选择菜单 插件已加载,它将增强新发现的所有选择 创建的页面.

While the page plugin no longer calls each plugin specifically, it does dispatch 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, just like before. For example, if the selectmenu plugin is loaded, it will enhance any selects it finds within a newly created page.

此结构现在允许我们添加一个新的create事件,该事件可以是 在任何元素上触发,从而节省了手动初始化的任务 该元素中包含的每个插件.到现在为止,如果开发者 通过Ajax或动态生成的标记加载到内容中,它们 手动初始化所​​有包含的插件(列表视图按钮, 选择等)以增强标记中的小部件.

This structure now allows us to add a new create event that can be triggered on any element, saving you the task of manually initializing each plugin contained in that element. Until now, if a developer loaded in content via Ajax or dynamically generated markup, they needed to manually initialize all contained plugins (listview button, select, etc.) to enhance the widgets in the markup.

现在,我们方便的create事件将初始化所有必要的插件 在该标记中,就像页面创建增强一样 过程的工作原理.如果要使用Ajax加载HTML块 标记(例如登录表单),您可以触发创建以自动 转换它包含的所有小部件(此中的输入和按钮 大小写)添加到增强版本中.此方案的代码为:

Now, our handy create event will initialize all the necessary plugins within that markup, just like how the page creation enhancement process works. If you were to use Ajax to load in a block of HTML markup (say a login form), you can trigger create 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事件之间存在重要区别 和某些小部件具有的刷新方法. create事件适合 用于增强包含一个或多个窗口小部件的原始标记.这 某些小部件具有的刷新方法应在现有组件上使用 (已增强)已通过编程方式操作的小部件 并需要更新用户界面以使其匹配.

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 that some widgets have should be used on existing (already enhanced) widgets that have been manipulated programmatically and need the UI be updated to match.

例如,如果您有一个页面,您在其中动态附加了新的 创建页面后,具有data-role = listview属性的无序列表, 在该列表的父元素上触发创建将对其进行转换 放入列表视图样式的小部件.如果还有更多列表项,那么 以编程方式添加,调用listview的refresh方法将 仅将这些新列表项更新为增强状态,然后将 现有列表项保持不变.

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.

这篇关于使用jQuery Mobile刷新表单页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆