动态添加可折叠元素 [英] Dynamically adding collapsible elements

查看:65
本文介绍了动态添加可折叠元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来源: http://jquerymobile.com/demos/1.0a2/#docs/content/content-collapsible.html 当我在代码中手动添加这样的元素时,它会正确显示. 但是当我尝试用jQuery这样添加它时:

Source: http://jquerymobile.com/demos/1.0a2/#docs/content/content-collapsible.html When I add an element like this manually to my code, it is displayed properly. But when I try to add it with jQuery like this:

$('body').append('<div data-role="collapsible"><h3>Title</h3><p>Content</p></div>');

它仅在h3中显示标题及其下方的内容,因此不显示为可折叠元素. 我该如何解决?

It just displays title in h3 and the content below it, so not as a collapsible element. How can I fix this?

推荐答案

最简单的方法是在动态创建的div上调用collapsible()方法:

The easiest way to achieve this is to call the collapsible() method on the dynamically created divs:

$('div[data-role=collapsible]').collapsible();

source: http://forum.jquery.com/topic/dynamically- add-collapsible-div

这篇关于动态添加可折叠元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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