在$ .post

编程入门 行业动态 更新时间:2024-10-11 05:22:09
在$ .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 });

更多推荐

本文发布于:2023-08-07 16:47:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465314.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:post

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!