有谁知道为什么下面的代码会在不同的浏览器中以不同的顺序执行?代码是在一个嵌入在纯 HTML 页面中的外部文件中,<body></body>
使用 <script src="js/filename.js"></script>
.
document.write("This is the first document.write()");
document.write("<br />followed by a second doc.write with br-element before");
document.write("<br /> and a third one doc.write with br before");
alert("now comes an alert() as fourth (will be expected)");
document.write("<br /> then there will be a fifth doc.write after the first alert");
document.write("<br />and a one more (sixth) doc.write after which an alert will be expected");
alert("the second alert at seventh position");
document.write("<br />and now the eight doc.write after the seventh alert");
Chrome 首先执行警报,然后是 docWrite,Edge 执行前 3 个 docWrite,然后是两个警报,然后是另一个 docWrite(也是错误的顺序)。只有 Firefox 以正确的顺序执行此代码。
同样的行为是当我在浏览器的开发人员工具中执行类似的代码时,例如:在一行中写一个document.write()
;后跟一个alert()
. Chrome 将首先执行alert()
as...
有没有人有任何想法?