jQuery.click();不要对特定的元素开火

jQuery .click() doesn't fire on particular element

本文关键字:元素 开火 click jQuery      更新时间:2024-03-14

当有人点击本网站主页上从一张幻灯片移动到另一张幻灯片的箭头(当您将鼠标悬停在浮动框上时会出现)时,我正在尝试注册:http://questtours-dc.com但由于某种原因,箭头是一个黑洞。

我有多个功能设置来记录点击,目前正试图弄清楚这一点。这是一个Wordpress网站,所以我必须通过$in.

jQuery(document).ready(function($) {
  $(document).click(function(){
    console.log(' A click has occurred ');
  });
  $(".et-arrow-next").click(function(){
    console.log(' You clicked the arrow ');
  });
  $(".et-slider-arrows").on('click','.et-arrow-next',function(){
    console.log(' 1 - You clicked the arrow ');
  });
  $("a.et-arrow-next").on('click',function(){
    console.log(' 2 - You clicked the arrow ');
  }); 
  $('#et-slider-wrapper').on('click','.et-arrow-next', function() {
    console.log(' 3 - You clicked the arrow');
  });
});

当您单击页面上除浮动框两侧的两个箭头外的任何位置时,它会记录一次单击。但是,每当你点击一个箭头,它什么都没有记录。

编辑:这也不起作用。添加在前两个回复之后。

$(".et-arrow-next").on("click", function() {
  console.log(' You clicked the arrow '); 
}); 

编辑2:在悬停开始后尝试以类为目标也不起作用

$('#et-slider-wrapper:hover .et-slider-arrows a').on('click', function() {
  console.log(' 4 - You clicked the arrow ');
});
$('#et-slider-wrapper:hover .et-arrow-next').on('click', function() {
  console.log(' 5 - You clicked the arrow ');
});

如果您尝试单击的元素是从javascript动态生成的,请使用

$( ".et-arrow-next" ).on( "click", function() {
     console.log(' You clicked the arrow ');
});

当你将鼠标悬停在浮动框上时,它就会出现

如果它被动态地附加到页面上(这意味着当文档准备好时它实际上并不存在),那么你必须使用on()方法,如下所示:

$(".someclass").on("click", function(){
    // your code
});