无法使用Bootstrap插件工作

时间:2015-10-04 21:01:50

标签: javascript jquery css twitter-bootstrap

http://jsfiddle.net/jzhang172/s83yt1L6/

我无法按下按钮。它应该像bootstrap网站上的工作一样:

http://getbootstrap.com/javascript/#buttons



<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<button type="button" id="myButton" data-loading-text="Loading..." class="btn btn-primary" autocomplete="off">
  Loading state
</button>

<script>
    $(function(){
  $('#myButton').on('click', function () {
    var $btn = $(this).button('loading')
    // business logic...
    $btn.button('reset')
  });
    });
</script>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:2)

您在更改为“加载”按钮后立即重置按钮。所以你不能看到它改变了。

&#13;
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<button type="button" id="myButton" data-loading-text="Loading..." class="btn btn-primary" autocomplete="off">
  Loading state
</button>

<script>
    $(function(){
  $('#myButton').on('click', function () {
   
    var $btn = $(this).button('loading');
    setTimeout(function(){$btn.button('reset');}, 1000);
    // business logic...
    
  });
    });
</script>
&#13;
&#13;
&#13;