簡體   English   中英

jQuery .click()不會觸發特定元素

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

當有人點擊本網站主頁上從一張幻燈片移動到另一張幻燈片的箭頭(當你將鼠標懸停在浮動框上時出現)時,我正在嘗試注冊: 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
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM