如何使用Ajax使Twitter Bootstrap Collapse在动态加载的html上工作 [英] How to make Twitter Bootstrap Collapse work on dynamically loaded html using ajax
问题描述
我正在使用 ajax 调用加载html,此html具有 Bootstrap Collapse .问题是折叠不起作用,如果您单击它会展开但不会再次折叠.
I am loading html using ajax call, this html has Bootstrap Collapse. The issue is Collapse is not working, if you click it will expand but it won't collapse again.
要检查我是否做错了什么,我将相同的代码放在静态页面上(未使用Ajax加载),并且工作正常.因此,似乎只有动态加载的html才有问题.
To check if I am doing something wrong, I put the same code on a static page (not loaded using ajax) and it works fine. So its seems issue only with dynamically loaded html.
我尝试使用
$(".collapse").collapse()
但仍然是相同的问题.
but still same issue.
我猜我需要使用jquery的live() / on()
方法,因为html是动态的,但是不确定如何调用$(".collapse").collapse()
,因为我认为它仅适用于事件或我需要其他东西要做?
I guess I need to use jquery's live() / on()
methods, because the html is dynamic, but not sure how do I do that for calling $(".collapse").collapse()
because I think it only works on events or is it something else that I need to do ?
推荐答案
我建议您致电
$(".collapse").collapse()
在添加动态html之后,在ajax的成功函数中.
inside the ajax's success function after the dynamic html is appended.
这篇关于如何使用Ajax使Twitter Bootstrap Collapse在动态加载的html上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!