【问题标题】:How to bind progress bar (use Ladda) with a button after button clicks in HTML?如何在 HTML 中单击按钮后将进度条(使用 Ladda)与按钮绑定?
【发布时间】:2015-01-26 03:30:23
【问题描述】:

我有一个进度条和一个按钮点击。现在进度条没有与按钮链接。那么我怎样才能确保:当按钮单击时,进度条开始;从服务器检索结果时,进度条会停止吗?身体能帮忙吗?

我想尝试有一些隐藏字段作为标志来通知进度条,但还没有时间尝试。

HTML 按钮在这里:

<section class="progress-demo">
            <button id="sendRequest_1" onclick="SendRequest(1)" type="button" class="btn btn-danger ladda-button" data-style="expand-left"><span class="ladda-label">Send</span></button></section>

进度条正在使用

<script src="js/spin.min.js"></script><script src="js/ladda.min.js"></script>

进度条在这里:

      <script>
        // Bind normal buttons
       Ladda.bind( 'section:not(.progress-demo) button', { timeout: 2500 } );

        //Ladda.bind( 'input[type=submit]' );

        // Bind progress buttons and simulate loading progress
        Ladda.bind( 'section.progress-demo button', {
            callback: function( instance ) {
                var progress = 0;
                var interval = setInterval( function() {
                    progress = Math.min( progress + Math.random() * 0.1, 1 );
                    instance.setProgress( progress );
                    if( progress === 1 ) {
                        instance.stop();
                        clearInterval( interval );
                    }
                }, 200 );
            }
        } ); 

按钮点击功能来了。

function SendRequest(i){
alert("button clicked!");
//call post to get server response
... say 1s to get response
//how to bind it to progress bar when server response is back??

}

【问题讨论】:

    标签: javascript jquery html css progress-bar


    【解决方案1】:
    ...
    var l = Ladda.bind( 'section:not(.progress-demo) button', { timeout: 2500 } );
    ...
    
    function SendRequest(i){
      $.ajax({
        url: "some.php",
        success: function(data){
          l.stop();
        }
      });
    }
    

    【讨论】:

    • 嗨,我尝试使用这个 var l = Ladda.create("#getsystem");但它给了我错误 - ladda.min.js:8 Uncaught TypeError: undefined is not a function。我已经包含了 ,它还是给了我这个错误?跨度>
    • 我在您的第一条消息中没有看到此代码。你改代码了吗?给我看看你的代码。
    • 抱歉,#getsystem 是一个按钮 ID,我可以使用 #sendRequest_1 代替。发生在我身上的问题是:Chrome 开发者工具会告诉我:undefined function, for l.stop();从你的建议。但是我已经在 html 页面中包含了 2 个 js 文件。不知道怎么了。谢谢。
    • 即使这篇文章很旧,我也遇到了同样的问题。你找到解决办法了吗?
    猜你喜欢
    • 2016-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多