关于传递给在单击事件时调用的函数的参数,我对 Firefox 4 的行为有疑问。
看看这个例子:
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/mootools/1.11/mootools.js"></script>
</head>
<body>
<span id="e">Klick mich!</span>
<script type="text/javascript">
$("e").addEvent("click", function(a, b, c){
alert(this);
alert(a);
alert(b);
alert(c);
console.log(this);
console.log(a);
console.log(b);
console.log(c);
}.bind(1, [2, 3]));
</script>
</body>
</html>
如果你用 Firefox 4 打开它,结果是:
- 1
- 2,3
- 对象鼠标事件
- 不明确的
在任何其他浏览器中,结果是:
- 1
- 2
- 3
- 不明确的
如您所见,只有 Firefox 4 将 MouseEvent 传递给该函数。这种行为破坏了我的很多代码。
你知道有什么解决办法吗?感谢帮助。
EDIT1:Chrome 的行为类似于 FF4