2014-11-06 60 views
3

最近正在處理圖像地圖並嘗試在圖像地圖上進行懸停操作。自然我第一次嘗試.hover(),但那不起作用,所以當我嘗試.mouseover()工作。爲什麼.hover()不能在映射的圖像上工作,但.mouseover()呢?

我的問題是,爲什麼一個人工作,而不是另一個?

/*This function works*/ 
$(document).on('mouseover', '#some-map', function(){ 
    console.log('I am hovering with mouseover()'); 
}).on('mouseout', function(){ 
    console.log('I am no longer hovering with mouseover()'); 
}); 

/*This function does not work*/ 
$(document).on('hover', '#some-map', function(){ 
    console.log('This is from hover()'); 
}, function(){ 
    consoel.log('Out from hover()'); 
}); 

回答

1

有AR沒有在(「懸停」 ......在jQuery的方法,你可以把它寫這樣

$('#some-map').hover(function(){ 
    alert('This is from hover()'); 
}, function(){ 
    alert('Out from hover()'); 
}); 
+0

啊,好吧。這是有道理的呢。所以我將如何創建一個懸停事件?用於動態創建的元素 – Adjit 2014-11-06 17:08:28

+0

我總是習慣這樣寫:。

相關問題