javascript - 如何实现ladda-bootstrap按钮加载动画?

标签 javascript jquery twitter-bootstrap

这是 github 文档:https://github.com/msurguy/ladda-bootstrap

我试图让我的代码工作,但由于某种原因,ladda 不会停止旋转(按钮永远不会再次启用),即使我放置“Ladda.stopAll();” AJAX 调用之后。这是我的代码:

<button type="button" class="btn btn-lg btn-success ladda-button" data-style="expand-left" id="genPDF"><span class="ladda-label">Generate PDF</span></button>

<script>

    Ladda.bind('button[id=genPDF]');

    $('#genPDF').click(function () {

        //Another approach I tried
        //Ladda.bind(this);

        var str = "tmName=" + $("#tmName").val() +
            "&headingText=" + $("#headingText").val();

        $.ajax({
            url: "testing.php",
            data: str,
            cache: false,
            success: function (data) {
                //None of this code matters, it all works fine
                console.log(data);
                var container = document.getElementById("pdfContainer");
                var content = container.innerHTML;
                container.innerHTML = content;
            }
        });

        //If I placed Ladda.stopAll(); here, the ladda wouldn't even
        //START spinning upon being clicked on.
    });

</script>

最佳答案

用这个就可以了

$('#yourladda_btn').click(function(){
    var l = Ladda.create(this);
    l.start();
    $.ajax({
        url: 'test.php',
        type: "post",
        data: {"yourdata":"test"},
        success: function(){

        }

    }).always(
            function() {
                l.stop();
            }
    );
});

关于javascript - 如何实现ladda-bootstrap按钮加载动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36876094/

相关文章:

javascript - 在 Javascript/jQuery 中添加带有变量的大块 HTML

javascript - 如何使用 BackboneJS 获取/users/profile 和/users/friends

javascript - 如何不断更新我正在使用JS播放的mp3文件的持续时间?进度栏不起作用

javascript - 在 Twitter BootStrap 嵌套下拉列表中托管一个选择列表(特定于 IE 9)

javascript - javascript 中的 Object.create 方法

javascript - CTRL+F 移动溢出 :hidden <div>

jquery - FadeToggle/SlideToggle 只能工作一次

jquery - 从动态生成的列表中选择多个项目 - Zend Framework

html - 如何在右键单击时更改下拉菜单的背景颜色?

jquery - Bootstrap 选项卡式内容未正确隐藏