jQuery不会在Safari的表单提交中运行 [英] jQuery doesn't run in Safari on form submit

查看:91
本文介绍了jQuery不会在Safari的表单提交中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个特殊的问题,这让我头疼...下面的代码在Firefox中可完美运行,但在Mac OS上的Safari中无法正常运行.

I have a peculiar issue which is giving me headaches... The following code works perfectly in Firefox but not in Safari on Mac OS.

我要在上传文件时显示一个简单的正在加载消息".所以我的页面看起来像这样:

I want to display a simple "Loading message" while files are being uploaded. So my page looks like this:

<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>
        <script>
            $(document).ready(function () {
                $('#upload').on('submit', function () {

                    $("#loading").fadeIn();

                });

            });
        </script>
    </head>

    <body>
        <p id="loading" style="display:none">UPLOADING...</p>


            <form name="upload" id="upload" method="post" action="upload.php" enctype="multipart/form-data">
                <input type='file' name='file[]' multiple/>
                <input type="submit" value="Upload..."/>
            </form>

    </body>
</html>

在Firefox上,正在上传文件时显示"UPLOADING ..."行,然后才将我转移到upload.php.在Safari上,正在上传..."行不显示,一旦文件上传,它会将我转移到upload.php.

On Firefox, the "UPLOADING..." line shows up while the files are uploading before transfering me to upload.php. On Safari, the "UPLOADING..." line doesn't show and it transfers me to upload.php once the files are uploaded.

如果Safari不支持此功能,我该如何实现完全相同的功能?

If this is something not supported in Safari, how can I achieve exactly the same feature?

谢谢您的帮助!

推荐答案

好,我知道了它的作用...

Ok, I got it working...

我使用id ='send'的'button'代替了'submit'按钮.我修改了脚本,使其首先在单击时显示p标签,然后在回调中添加表单提交,如下所示:

Instead of a 'submit' button, I changed it by a 'button' with id='send'. I modified the script to first show the p tag on click and then added the form submit in the callback like so:

<script>
            $(document).ready(function () {

                $("#send").click(function () {

                    $("#loading").fadeIn(function () {
                        $("#upload").submit();
                    });

                });

            });
</script>

它现在可以在所有浏览器中使用.在IE,FF,Chrome和Safari中进行了测试.

And it works in all browsers now. Tested in IE, FF, Chrome and Safari.

这篇关于jQuery不会在Safari的表单提交中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆