Firefox 4 新点击事件行为的问题
我对 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
- object MouseEvent
- undefined
在任何其他浏览器中,结果是:
- 1
- 2
- 3
- undefined
正如你所看到的,只有 Firefox 4 将 MouseEvent 传递给函数。这种行为破坏了我的很多代码。
你知道有什么解决办法吗?感谢您的帮助。
EDIT1:Chrome 的行为类似于 FF4
I have a problem with the behavior of Firefox 4 in regards to parameters passed to the function that is getting called upon a click event.
Take a look at this example:
<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>
If you open this with Firefox 4 the result is:
- 1
- 2,3
- object MouseEvent
- undefined
In any other browser the result is:
- 1
- 2
- 3
- undefined
As you can see only Firefox 4 passes an MouseEvent to the function. This behavior breaks a lot of my code.
Do you know any solution? Thanks for help.
EDIT1: Chrome behaves like FF4
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是 - 这是 mootools 1.11 -
mootools 1.11 中不支持且旧,它被接受使用( http://docs111.mootools.net/Native/Function.js#Function.bind ):
因此,执行 .bind(1, [args])
是正确的。然而,最近原生
Function.bind
实现在实现它的浏览器中发生了变化 - https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind这意味着,要使其工作,您需要
.bind(1,2,3,4);
其中 1 是绑定范围,2,3,4 是参数。你应该升级,在 Mootools 1.11 编写 4 年后的浏览器上运行它会产生不可预测的结果。总是。例如,1.11 将不再检测 gecko/ff,因为用于测试它的 func 已弃用。
接下来做什么,检查 netscape4? :)
the problem is - this is mootools 1.11 - UNSUPPORTED AND OLD
in mootools 1.11, it was accepted to use ( http://docs111.mootools.net/Native/Function.js#Function.bind ):
hence, doing .bind(1, [args])
was
correct. However, recently the nativeFunction.bind
implementation changed in browsers that implement it - https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bindit means, to make it work you need
.bind(1,2,3,4);
where 1 is bound scope and 2,3,4 are arguments.you SHOULD upgrade, running mootools 1.11 on browsers that came 4 years after it got written will yield unpredictable results. always. for example, 1.11 won't detect gecko/ff anymore due to deprecated func used to test for it.
what next, check for netscape4? :)