Jquery:附加后单击事件不起作用.(不知道如何使用.ON) [英] Jquery: Click event doesn't work after append. (Don't know how to use .ON)

查看:15
本文介绍了Jquery:附加后单击事件不起作用.(不知道如何使用.ON)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 2 个点击事件.一个附加一个包含另一个点击事件的 IMG.它显然不起作用.我知道我必须使用 jQuery 的 .ON,但我就是不知道如何以及在哪里.

I have 2 click events. One appends an IMG which includes another click event. It doesn't work obviously. I know that I have to use jQuery's .ON, but I just can't figure out how and where.

我的代码:

$( document ).ready(function() {
    // The one below (.choimh) isn't triggered anymore
    $('.choimg').click(function(){

    });

    // Switch to chosen color
    $('.color').click(function(){
        $(".thumbs").append('<a href="#"><img id="image'+u+'" class="choimg" src="/img/products/mini/'+colnumber+'-'+ i + '.jpg" />');
    });
});

.color div 与 .choimg 位于完全不同的位置.

The .color div is on a completely different place than .choimg.

我只是不知道如何使用 .ON.

I just can't figure out how to use .ON.

推荐答案

以前是 livedelegate 函数做这种事情.现在你可以这样做了:

It used to be the live or delegate functions that did this kind of thing. Now you can do it like this:

$(document).on('click', '.choimg', function(e) {

//do whatever

});

这篇关于Jquery:附加后单击事件不起作用.(不知道如何使用.ON)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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