Jquery:附加后单击事件不起作用.(不知道如何使用.ON)如何使用、单击、不起作用、事件

由网友(我不喜欢妥协)分享简介:我有 2 个点击事件.一个附加一个包含另一个点击事件的 IMG.它显然不起作用.我知道我必须使用 jQuery 的 .ON,但我就是不知道如何以及在哪里.I have 2 click events. One appends an IMG which includes another click event. It d...

我有 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

});
阅读全文

相关推荐

最新文章