动态创建按钮 - JQueryMobile

发布于 2024-10-09 09:09:37 字数 32 浏览 0 评论 0原文

如何使用 jQuertMobile 动态创建按钮。

How to create the button dynamically using jQuertMobile.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

尹雨沫 2024-10-16 09:09:37

非常简单:

首先通过以下方式创建一个按钮 HTML JQuery 元素:

var button = $("<button>My Button</button>");

接下来,将按钮注入到页面中您想要的任何位置:

$("#my_button_div").append(button);

最后在按钮上运行 button() JQuery Mobile 命令:

button.button();

您应该有一个功能性且 JQM 风格的按钮现在在您的页面中。

Very simple:

First create a button HTML JQuery element by:

var button = $("<button>My Button</button>");

Next, inject the button wherever you want it to be in the page:

$("#my_button_div").append(button);

And finally run the button() JQuery Mobile command on the button:

button.button();

You should have a functional and JQM styled button in your page by now.

路弥 2024-10-16 09:09:37

编辑:现在您触发的事件已完成。

.trigger('create')

详细信息和最新描述“如何让 JQM 处理我添加到 DOM 的内容?”在这里: http://jquerymobiledictionary.pl/faq.html

创建它,然后调用 page () 元素上。它将把 jquery mobile 中的所有插件和样式应用到您创建的任何元素。

EDIT: Now it's done with an event you trigger.

.trigger('create')

Details and up-to-date description "How do I make JQM work with content I add to DOM?" is here: http://jquerymobiledictionary.pl/faq.html

Create it and then call page() on the element. It will apply all plugins and styles from jquery mobile to any element you create.

作妖 2024-10-16 09:09:37

简单:

var button = $("<button>My Button</button>");
$("#my_button_div").append(button).trigger('create');

这里的例子: jquery mobile 动态创建网格

Simple:

var button = $("<button>My Button</button>");
$("#my_button_div").append(button).trigger('create');

here example: jquery mobile create grid dynamically

提赋 2024-10-16 09:09:37

上面的链接已损坏,该解决方案对我不起作用。

以下代码不起作用:

$(this.el).append("<button id='add2' data-role='button'>Add list item</button>");

$('#add2').page();

按钮已添加并且无需调用 $('#add2').page(); 即可完美运行,但它没有 JQuery Mobile 样式。因此,在将按钮添加到 DOM 后,调用 .page() 并不是应用样式的有效修复方法。

Above link is broken and the solution doesn't work for me.

The following code does not work:

$(this.el).append("<button id='add2' data-role='button'>Add list item</button>");

$('#add2').page();

The button is added and works perfectly without calling $('#add2').page(); but it has no JQuery Mobile styling. Calling .page() is therefore not a working fix for applying the styling after adding the button to the DOM.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文