JavaScript get original caller object
Here is a sample situation:
<smth onmouseover=&q开发者_开发技巧uot;test('hello')">
...
function test(pLabel)
{
var sender = ?;
var evt = ? || window.event;
}
In the function test()
- how do I get the object that I hovered the mouse on and the mouse event? I've tried playing with the callee property but didn't get it to work in IE.
It's best not to define your event handlers in the HTML itself. Try this:
<div id="something">...</div>
...
document.getElementById('something').onmouseover = function() {
// use `this` to reference the <div>
alert(this.id); // alerts "something"
};
精彩评论