【问题标题】:Animate form while it is submitted with jquery使用 jquery 提交时为表单设置动画
【发布时间】:2013-02-07 00:37:16
【问题描述】:

我不知道如何解释,但我会尽力而为... 我正在尝试正常提交表单,但请求结果将显示在 iframe 中。一切顺利到这里。我想要做的(如果可能的话)是动画形式将消息放入其中(如“发送......”)直到 iframe 加载响应。我现在很困惑,但是看看我的文件:

index.php

我省略了标题,因为它太明显了。

<form enctype="multipart/form-data" method="post" action="upload.php" target="my_iframe" id="form-upload">
    Choose your file here:
    <input name="uploaded_file" type="file"/>
    <input id="send-button" type="submit" value="Subir imagen"/>
</form>


<IFRAME name="my_iframe" SRC="upload.php" width="100%" height="200px" id="iframe1" marginheight="0" frameborder="0"></iframe>

<script type="text/javascript">
    $(document).ready(function(){
        $('#send-button').sendImage({formid: "form-upload"});
    });
</script>

上传.php

仅用于测试 porpuses。

<?php
if( isset($_FILES['uploaded_file']) )
    echo "image sent";

动画.js

这就是我要处理的地方。因为当我访问index.php 时,消息sending... 总是显示表单元素的实例。

var conf;

jQuery.fn.sendImage = function(args) {
    conf = $.extend( {
    }, args);


    this.on('click', function(e){
        e.preventDefault();
        $('#'+conf.formid).submit();
        $('#'+conf.formid).html('sending...');
    });

}

【问题讨论】:

    标签: php jquery html animation iframe


    【解决方案1】:

    一旦提交表单,当前页面上的所有处理都会停止。您所做的任何事情都必须在您实际提交表格之前进行。您的替代方法是通过 AJAX 提交。

    【讨论】:

    • 好吧,不能通过 ajax 替代,因为它无法发送/上传文件。出于这个原因,我使用了一个 html 表单元素。
    • 正如我所说,只要您在提交之前显示“正在发送...”面板,那么它可以显示 something,但在提交之后所有 JS 活动都会停止。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-20
    • 2015-10-14
    • 2012-08-02
    • 1970-01-01
    • 2011-02-13
    • 1970-01-01
    • 2011-08-04
    相关资源
    最近更新 更多