javascript - 进度条提交动画后提交表单

标签 javascript jquery html forms animation

我需要你的帮助。

我有一些带有动画的提交按钮,这是一个工作演示:

http://plnkr.co/edit/KhDdXWYnj3kVxhiKaEFL

但是现在提交不起作用,只能询问并播放动画。不提交表格

<button type="submit" name="send_approve" onClick="return message1()" class="progress-button" data-style="rotate-back" data-perspective data-horizontal>Enviar </button>

这是动画代码:

[].slice.call( document.querySelectorAll( 'button.progress-button' ) ).forEach( function( bttn ) {
            new ProgressButton( bttn, {
                callback : function( instance ) {
                    var progress = 0,
                        interval = setInterval( function() {
                            progress = Math.min( progress + Math.random() * 0.1, 1 );
                            instance._setProgress( progress );

                            if( progress === 1 ) {
                                instance._stop(1);
                                clearInterval( interval );
                            }
                        }, 200 );
                }
            } );
        } );

在动画之前我有这个并且工作正常,但现在我只想按下按钮,动画并提交而不进行确认验证

    function message1() {

             var r = confirm("¿ Sure to submit ?");
            if (r == true) {
            return true;

                            }
    else    {
            alert('it didnt work');
            return false;
            }   
                    }           

你知道我该怎么做吗? 感谢您的帮助!

最佳答案

好吧,如果您不想再提示该问题,请首先确保删除该 onclick 属性。 其次,确保您的按钮以及所有其他字段都包含在 form 标记内,如下所示:

<form name="theForm" method="GET" action="http://www.google.ro/search">
    <input name="q" type="text" placeholder="enter search keyword" />

    <button type="submit" <!-- rest of the attributes except for onclick -->>
         <!-- rest of the content, like those spans go here -->
    </button>
</form>

第三,在JS中,进度完成后只需提交表单:

if ( progress === 1 ) {
    instance._stop(1);
    clearInterval( interval );

    document.forms["theForm"].submit();
}

关于javascript - 进度条提交动画后提交表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24977466/

相关文章:

javascript - 优化js - 保存对象中复选框的值

javascript - 当我达到数字的倍数时在 JavaScript 循环中添加新行

javascript - 如何在 d3 图表中定位图例

javascript - 如何在 TypeScript 的监视模式下运行 Jasmine 测试

javascript - 在 jQuery 中添加指向特定短语或关键字的链接

jquery - jquery 中的 nextAll 不起作用

javascript - js文件导入顺序

html - 我创建的这个 HTML/CSS 页面上出现了一些不需要的边框

javascript - 隐藏右键菜单/点击嵌入 html 文件

javascript - HTML slider 问题