DOM에 요소를 추가하는 다른 클릭 이벤트를 트리거하는 클릭 이벤트가 있습니다. 편집 :하지만 두 번째 요소를 클릭하면 두 개의 요소가 추가되고 세 번째 요소는 두 개의 요소가 추가됩니다. jQuery 큐를 검사 할 때마다 매번 발생하는 큐에 이벤트를 추가했음을 확인합니다.jQuery에서 클릭 큐 지우기
내가 시도하려는 것은 다른 요소를 클릭하여 두 개의 드롭 다운 목록에 클릭 이벤트를 추가하는 것입니다.
$(".step-1 a").on("click", function(e){
e.preventDefault();
var userValue = $(this).attr('id');
$(".template-image").removeClass("selected");
$(this).children(":first").addClass("selected");
$("#page_template option ").each(function(){
var t = $(this);
var cValue = t.attr("value");
if(t.attr("selected") === "selected"){
t.removeAttr("selected");
}
if(t.attr("value") === userValue){
t.prop("selected", "selected");
$('#page_template').trigger('change');
var template = t.attr("value");
switch (template)
{
case "default":
$(".step-2").slideDown("fast");
$(".step-2").addClass("show");
break;
default:
$(".step-2").removeClass("show");
$(".step-2").slideUp("fast");
break;
}
}
});
});
$('.step-2 img').on("click", function(e){
e.preventDefault();
var userinput = $(this).attr('id');
$('.flexible-footer .acf-fc-add').each(function(){
var text = $(this).text();
if(text === "Add columns"){
$(this).trigger('click');
$('.flexible-footer .acf-fc-popup ul li a').each(function(){
var column = $(this).attr('data-layout');
if (column === userinput) {
$(this).trigger('click');
$(this).finish();
console.log($(this).queue());
}
});
}
});
나는이 시도하고 그것을 추가하면 클릭 이벤트가 다시 발생하는 것을 막을 것으로 보인다. 또한 첫 번째 클릭이 한 번의 클릭 이벤트를 발생시키고 두 번째 클릭이 두 번의 클릭 이벤트를 발생시키고 클릭이 두 번 발생하는 것으로 나타났습니다. –
첫 번째 실행에서 이벤트 큐를 지우려면 http://api.jquery.com/clearQueue/를 시도해보십시오. –
팁 주셔서 감사합니다. 나는 그것을 시도했지만 효과를 얻지 못했지만, 다시 시도하고 그것이 효과를 발휘할 수있는 방법을 찾을 수 있는지 알아볼 것입니다. –