jQuery的:单击事件后追加不工作。 (不知道怎么用.ON) [英] Jquery: Click event doesn't work after append. (Don't know how to use .ON)
本文介绍了jQuery的:单击事件后追加不工作。 (不知道怎么用.ON)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个click事件。其中追加一个IMG,其中包括另一个click事件。它不显着工作。我知道,我必须使用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.
我的code:
$( 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" />');
});
});
本。颜色DIV是一个完全不同的地方比.choimg。
The .color div is on a completely different place than .choimg.
我只是无法弄清楚如何使用.ON。
I just can't figure out how to use .ON.
推荐答案
这曾经是生活
或委托
该做这种事情的功能。现在,你可以做到这一点是这样的:
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屋!
查看全文