开发者

how to get src element in javascript for firefox

I am try to catch form event in javascript

var event = window.event.srcElement;

This is working fine in IE, but in Netscape/Firefox where eve开发者_如何学Cnt return undefined.

Can someone tel me how to catch event in Netscape/Firefox?


IE and Netscape play different games. But you can easily make it crossbrowser as such:

if (window.event) e = window.event;
var srcEl = e.srcElement? e.srcElement : e.target; 


Use .target:

var event = event.target;

Or to check for both/fallback in a single statement:

function myHandler(event) {
  var target = window.event.srcElement || event.target;
}

(In both cases... I'd rename your variable, since this isn't the actual event object, but an element.)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜