Safari 7.0.1和onsubmit

Tom*_*com 14 html javascript safari onsubmit

由于Safari(7.0.1/Mac OS),我正在努力解决一个简单的Javascript问题.我提交了一个表单,我希望在页面加载期间显示一个图标.

从我所看到的,它与javascript本身无关,而是与onsubmit行为有关(如果我将它移到函数之外,它在加载页面而不是"提交"时间时执行预期的工作).

这是我的代码(在Chrome和Firefox上完美运行).任何的想法?

<html>
<body>    
  <img id="loadingImage" src="assets/images/loadingIcon.png" style="display:none;"/>
  <form method="POST" action="js.php" onsubmit="loadLoader()">
    <input type="submit" value="Go"/>   
  </form>

<script  type="text/javascript">
function loadLoader(){
    document.getElementById('loadingImage').style.display = 'block';
    return true;
}
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

小智 1

抱歉,由于我的声誉,我无法评论您的帖子。由于 JS 代码是非阻塞的,我尝试将其移至头部并javascript在函数调用之前添加。我在 Safari 7.0.1 中测试了它并且有效。

<html>
<head>
    <script type="text/javascript">
        function loadLoader() {
            alert('loadLoader called');
            document.getElementById('loadingImage').style.display = 'block';
            return true;
        }
    </script>
</head>

<body>
    <img id="loadingImage" src="assets/images/loadingIcon.png" style="display:none;" />
    <form method="POST" action="js.php" onsubmit="javascript:loadLoader()">
        <input type="submit" value="Go" />
    </form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)