Firefox 上的 Javascript 在 onchange 任务上意外停止执行

Javascript on Firefox stops execution unexpectedly on an onchange assignment

本文关键字:意外 执行 任务 上的 Javascript onchange Firefox      更新时间:2023-09-26

以下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语句。