2016-01-07 268 views
0

我想改變這一點(這在我的表得到一個跨度名):更改jQuery的鼠標懸停到窗口鼠標懸停

$('span').on('mouseover', function() { 
    if (this.id.match(/_zUserId/)) { 
     alert(this.id); 
    } 
} 

要使用:

window.onmouseover=function(e) { 
    ... 
    ... 
} 

但我無法弄清楚如何從e.target獲得跨度名稱。在e.target之後我不知道該如何獲取span名稱。

+0

是什麼'e.target.id'給你?你應該可以在有'this'的地方使用'e.target'。 – nnnnnn

+0

它是空白的。這是如何爲我想要鼠標懸停的項目設置表格。該表是使用網站創建程序創建的。 <跨度ID = 「el3_zUserId」 類= 「tblCertifications_zUserId」> [email protected] ready4data

+0

我爲此發佈了答案,但我建議您使用調試器查看對象的所有方法,是檢查真實世界中真實對象的最簡單方法。使用chrome或firebug的控制檯,停止存在對象的函數中的代碼,並檢查對象是否暴露。 – Baro

回答

0

Here the JSFiddle example.

window.onmouseover=function(e) { 
    if (e.target.id=='mySpan') { 
     alert(e.target.id); 
    } 
} 
+0

它必須與如何構建表有關。 jquery函數可以正常工作,但e.target.id不會使用window.onmouseover函數返回任何內容。 – ready4data

+0

@ ready4data你可以發佈你的表的HTML嗎?以及您嘗試使用onmouseover事件執行的實際JS? – Baro