簡體   English   中英

檢查元素是否懸停在上面

[英]check if an element is being hovered over

我想檢查一個元素是否正在盤旋。 我收到此錯誤:

Syntax error, unrecognized expression: unsupported pseudo: hover

當我使用這段代碼時:

 $('.class').blur(function(){
    if(!$(this).is(':hover')){
       //element not being hovered over
    }
 });

我也試過這個:

 $('.class').blur(function(){
    if($(this+":hover").length === 0){ 
       //element not being hovered over
    }
 });

這也行不通。 有沒有其他方法可以做到這一點。 謝謝。

$(".class").mouseover(function(){   
    $(this).attr('checked',true);   
    });  
});

jQuery內置了這個功能。 請參閱.hover()上的文檔

$(".class").hover(
  function() {
    // item is being hovered over
    $(this).addClass('hover');
  }, function() {
    // item is no longer being hovered over
    $(this).removeClass('hover');
  }
);

暫無
暫無

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

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