开发者

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"
};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜