I just ran into an issue with setTimeout()
on Firefox that seems like it would be a huge problem if everyone had it, yet I see no mention of it when I search around for it… so I'm wondering if I've screwed this up locally somehow.
我刚刚在Firefox上遇到了setTimeout()的问题,如果每个人都有这个问题,这似乎是一个很大的问题,但是当我搜索它时我没有提到它...所以我想知道我是否已经搞砸了这在某种程度上在当地。
The problem is illustrated very clearly by this W3Schools TryIt page. For posterity, the code is as follows:
W3Schools TryIt页面非常清楚地说明了这个问题。对于后代,代码如下:
<!DOCTYPE html>
<html>
<body>
<p>Click the Start button to output "Hello" after 2 seconds.</p>
<p>In this example, we also output the parameters that were passed to the alertFunc() function (does not work in IE9 and earlier).</p>
<button onclick="myStartFunction()">Start</button>
<p id="demo"></p>
<p id="demo2" style="color:red;"></p>
<script>
var myVar;
function myStartFunction() {
myVar = setTimeout(alertFunc, 2000, "First parameter", "Second parameter");
}
function alertFunc(param1, param2) {
document.getElementById("demo").innerHTML += "Hello ";
document.getElementById("demo2").innerHTML = "Parameters passed to alertFunc(): <br>"
+ param1 + "<br>" + param2 + "<br>";
}
</script>
</body>
</html>
When I do this in Chrome (currently Version 53.0.2785.101 m (64-bit)
, it works. When I do it in Firefox (currently 48.0.2
), it fails (both parameter values come out as undefined
).
当我在Chrome中执行此操作(当前版本为53.0.2785.101 m(64位)时,它可以正常工作。当我在Firefox(当前为48.0.2)中执行此操作时,它会失败(两个参数值都是未定义的)。
1 个解决方案
#1
0
Found it. Turns out RightToClick is overriding setTimeout with its own version (which doesn't accept the extra parameters).
找到了。结果是RightToClick用自己的版本覆盖了setTimeout(它不接受额外的参数)。
#1
0
Found it. Turns out RightToClick is overriding setTimeout with its own version (which doesn't accept the extra parameters).
找到了。结果是RightToClick用自己的版本覆盖了setTimeout(它不接受额外的参数)。