jQuery的点击不工作的AJAX生成的内容 [英] jquery click doesnt work on ajax generated content
本文介绍了jQuery的点击不工作的AJAX生成的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 $(按钮)上(点击,函数(){});
要点击一个按钮,这是对一个容器中,但随后一个Ajax调用完成和内容
得到更新与新的东西,然后当我尝试点击 .button
它不会工作...当我按一下按钮什么也不会得到恢复。
我甚至尝试
$(按钮)生活(点击,函数(){});
或
$(按钮)点击(函数(){});
我怎样才能使它工作?
编辑: 我的html:
< DIV CLASS =容器>
< UL>
<李> ITEM1< /李>
<李>项目2< /李>
<李>项目3< /李>
< / UL>
<输入类型=按钮值=重载类=键/>
< / DIV>
解决方案
确定我使用。对()函数正确,因为我缺少一个参数,解决了我的问题。
而不是
$(按钮)上(点击,函数(){})。
我用
$(容器)上(点击,.button,函数(){})。
I am using $(".button").on("click", function(){ });
to click to a button which is on a container but then an ajax call is done and the content
gets updated with new stuff and then when i try to click .button
it wont work... nothing will get returned when i click the button.
I even tried
$(".button").live("click", function(){ });
or
$(".button").click(function(){ });
How can I make it work?
EDIT : my html:
<div class="container">
<ul>
<li>item1</li>
<li>item2</li>
<li>item3</li>
</ul>
<input type="button" value="reload" class="button" />
</div>
解决方案
Ok i solved my problem by using the .on() function correctly since i was missing one parameter.
instead of
$(".button").on("click", function() { } );
i used
$(".container").on("click", ".button", function() { } );
这篇关于jQuery的点击不工作的AJAX生成的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文