itoracja 发表于 2013-2-3 10:15:32

ie 火狐 获取事件源对象

以防自己忘记~~js获取事件event,不同浏览器有不同的做法。
例如ie下,在js函数中,通过window.event就可以获取,不必在函数中添加什么参数。
</span>
<span style="color: #000000; font-size: small;"><span style="color: #ff0000;">也可以用prototype或者jquery等,它们有他们对事件的包装。还是使用js库比较好,不然就有下边的麻烦。</span>
firefox:要传递参数
<head><script>function click1(event,str1){alert(event+str1);}</script></head><body><input type="button" id="abc"value="click me"/></body> ie:不需要传递参数
<head><script>function click1(){alert(event.srcelement.value);}</script></head><body><input type="button" id="abc"value="click me"/></body> 
<div style="font-family: arial; font-size: 12px; line-height: normal; overflow: hidden;"><div style="font-family: arial; font-size: 12px; line-height: normal; overflow: hidden;"><span style="line-height: normal; font-size: 13px; color: #333333;">在ie下,event对象有srcelement属性,但是没有target属性;firefox下,even对象有target属性,但是没有srcelement属性.。<p style="line-height: normal;"><span style="line-height: normal; font-size: 13px; color: #333333;">    解决方法:使用obj(obj = event.srcelement ? event.srcelement : event.target;)来代替ie下的event.srcelement或者firefox下的event.target.。同时注意event的 兼容性问题。 <br style="line-height: normal;"></span>}
页: [1]
查看完整版本: ie 火狐 获取事件源对象