Firefox中window.event(firefox对象事件)

来看以下代码:

<html>
  <head>
  	<title>eventTest</title>
	<script type="text/javascript">
		function aaa(ev){
			var e = ev || window.event;
			alert(e)
		}
	</script>
  </head>
  <body>
  	<label id="aaa" onclick="aaa()">aaaaaaa</label>
  </body>
</html>

点击页面中的aaaaaa,在javascript代码chrome中可以正常执行,在firefox中无法正常执行

原因在于,我们必须在onclick=“aaa()”,这里传入event,而且必须是event,如下:

<html>
  <head>
  	<title>eventTest</title>
	<script type="text/javascript">
		function aaa(ev){
			var e = ev || window.event;
			alert(e)
		}
	</script>
  </head>
  <body>
  	<label id="aaa" onclick="aaa(event)">aaaaaaa</label>
  </body>
</html>

以上代码再firefox中也可以正常执行了

参考地址:

http://dbear.iteye.com/blog/814509

posted @ 2015-08-13 21:18  远洪  阅读(525)  评论(0)    收藏  举报