如何使用jQuery mobile确保动态DOM元素具有正确的css [英] How to make sure that dynamic DOM elements have correct css using jQuery mobile

查看:42
本文介绍了如何使用jQuery mobile确保动态DOM元素具有正确的css的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery mobile构建移动应用程序。
我尝试动态添加一些输入,但是,jQuery移动样式不会添加到动态创建的输入中。
我创建了一个简单的应用程序: http://jsfiddle.net/jGhqS/

I am building a mobile app using jQuery mobile. I try to add some inputs dynamically, however, jQuery mobile style is not added to dynamically created input. I have created a simple app: http://jsfiddle.net/jGhqS/

我希望我的所有新输入都继承默认的jQuery mobile css。
我该怎么办?
为什么它默认不起作用?

I would like to have all my new inputs inherit default jQuery mobile css. How do I do it? And Why is it not working by default?

动态添加输入的代码:

$('#pageone').append("<input id='laskaInput' type='email' name='email' placeholder='1@1.com'>");


推荐答案

尝试。trigger(create)

 $('#pageone').append("<input class='laskaInput' type='email' name='email' placeholder='1@1.com'>")
            .trigger("create");



您附加的元素具有相同的 ID 很多次。 ID 必须是唯一的使用 class 而不是


you are appending elements with same ID many times .ID must be unique use class instead

阅读具有相同id属性的两个HTML元素:它有多糟糕?

小提琴演示



jQuery mobile在Page load中添加自己的样式和类。稍后添加的元素需要 .trigger(create) ; 以便jQuery mobile为添加的新元素添加样式和类。

fiddle Demo


jQuery mobile adds its own styles and classes at Page load.The element which are added later need to .trigger("create"); so that jQuery mobile adds styles and classes to new elements added .


注意: - 重要的是要记住必须在父容器的
上触发创建,而不是在需要增加
的单个元素上触发。

Note:- It is important to remember that create must be triggered on the parent container and not on the individual element that needs to be enhanced.

阅读在注入的HTML上触发创建不起作用。

这篇关于如何使用jQuery mobile确保动态DOM元素具有正确的css的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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