2011-09-26 23 views
0

下面是一個簡單的情況:的Javascript得到原調用對象

<smth onmouseover="test('hello')"> 
... 
function test(pLabel) 
{ 
    var sender = ?; 
    var evt = ? || window.event; 
} 

在功能測試() - 我如何得到我徘徊在鼠標和鼠標事件的對象?我試過玩callee屬性,但沒有得到它在IE中的工作。

回答

0

最好不要在HTML本身中定義事件處理程序。試試這個:

<div id="something">...</div> 

...

document.getElementById('something').onmouseover = function() { 
    // use `this` to reference the <div> 
    alert(this.id); // alerts "something" 
}; 
+0

-1,因爲雖然這是很好的建議,這不是在所有原來的問題有關,也有幫助。 – KOGI