在$ .post-loaded按钮上单击按钮事件(Button click event on $.post-loaded button)
在使用$(myDiv).load()调用填充div之后,我想在该div内的按钮上捕获click事件。
现在由于某种原因,当我点击通过jQuery的加载函数加载的按钮时,我的$('.myButton').click没有被调用。
围绕这个的最佳方法是什么?
After filling a div with a $(myDiv).load() call, I want to catch the click event on the button inside that div.
Now for some reason my $('.myButton').click is not invoked when I click on a button that is loaded through jQuery's load function.
What is the best way around this?
最满意答案
你必须捕获一个动态对象的事件,为此你必须使用.on()试试这个:
$(document).on('click', '.myButton', function(){ //your code });代替
$('.myButton').click(function(){ //your code });You have to catch an event of a dynamic object, to do this you have to use .on() try this:
$(document).on('click', '.myButton', function(){ //your code });instead of
$('.myButton').click(function(){ //your code });更多推荐
发布评论