Firefox 上的 Javascript 在 onchange 赋值时意外停止执行

标签 javascript google-chrome firefox

以下 JavaScript 代码片段在 Google Chrome 上完美运行,但在 Firefox 上出现第二个警报之前不会继续:

init.js:

function __init__() {
    alert("welcome!");
    document.getElementById("myselector").onchange = foo;
    alert("must go here");

    // some other initialization code goes here

    alert("must end here");
}

window.onload = __init__;

foo.js:

function foo() {
    // some other code for function foo
    break;
    // the rest of the code
}

然而,Firefox 或 Chrome 的开发者工具控制台没有报告任何错误,这让我沮丧了好几天。

最佳答案

在循环或 switch 语句中不使用任何 break 语句时,请将其删除。

关于Firefox 上的 Javascript 在 onchange 赋值时意外停止执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19176090/

相关文章:

javascript - 如何使用 Javascript 在 Chrome 中检测选项卡何时聚焦或不聚焦?

firefox - 禁用 "Prevent this page from creating additional dialogs"

jquery - 设置选择的字体系列在 firefox 中有效,但在 chrome 中无效

javascript - 如何引用动态创建的拉斐尔 Canvas ?

javascript - 将图表鼠标事件传递给格式化标签

javascript - 如何通过 jquery 调用使用 jquery 设置的选定选项 php 变量?

firefox - 在 Jupyter 终端中删除单词时如何避免关闭浏览器选项卡?

xml - 为什么 E4X 被弃用并从某些浏览器中删除?

javascript - Firefox 不支持 Angular 方向更改事件

javascript - CSS 动画在恢复之前下降