javascript 在不同浏览器上的执行

问题描述

单击下面代码中的“单击我”按钮,我在 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>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)