0

单击下面代码中的“单击我”按钮,我观察到 Firefox 和 Brave/Chrome 上的不同行为。以下是每个浏览器的行为,当单击“单击我”按钮时:

  1. Firefox:显示隐藏文本,然后弹出确认框。
  2. Brave/Chrome:弹出确认框,并在响应(单击确定或取消)确认框后显示隐藏文本。

我的问题是,由于显示隐藏文本的代码出现在确认框代码之前,为什么它的行为与 Brave/Chrome 中的行为一样?

隐藏文本不应该在所有浏览器中始终显示在确认框之前吗?还是我错过了什么?

<!Doctype html>
<html>
    <head>
        <title>js execution test</title>

        <style>
            #some-text {
                display: none;
            }
        </style>
    </head>

    <body>
        <div id="some-text">some text here to read</div>

        <button type="button" onclick="invokeMe()">click me</button>

        <script>
            function invokeMe() {
                let someText = document.getElementById("some-text");

                someText.style.display = "block";
                someText.style.fontSize = "3em";

                confirm("doesn't matter if you choose ok or cancel");
            }
        </script>
    </body>
</html>
4

0 回答 0