admin管理员组

文章数量:1389762

I want have have a "Loading. . ." whenever I click on the "Submit" button. In this case, how e it did not display the "Loading. . ." thingy? bootstrap 2.3.2

<input type="submit" data-loading-text="Loading..." disabled="disabled" style="" id="save" class="btn btn-primary " value="Submit" name="save">

Here's my JS:

$('#save').click(function() {
    var btn = $(this);
    btn.button('loading');
    btn.button('reset');
});

I can't find any error in console either. What did I miss?

I want have have a "Loading. . ." whenever I click on the "Submit" button. In this case, how e it did not display the "Loading. . ." thingy? bootstrap 2.3.2

<input type="submit" data-loading-text="Loading..." disabled="disabled" style="" id="save" class="btn btn-primary " value="Submit" name="save">

Here's my JS:

$('#save').click(function() {
    var btn = $(this);
    btn.button('loading');
    btn.button('reset');
});

I can't find any error in console either. What did I miss?

Share Improve this question edited Aug 9, 2015 at 18:13 Siguza 24k6 gold badges55 silver badges99 bronze badges asked May 11, 2015 at 8:30 ZSMJZSMJ 992 silver badges5 bronze badges 4
  • 3 .button? .. Sounds interesting..! perhaps you wanted .val() instead? Also, this is a submit, you should prevent it's default value, else it will reload the document! ;) Something like that? jsfiddle/cmfc6qLL (the setTimeout is just for an example purpose, some kind of delay to show that both "loading" and "reset" are written) – briosheje Commented May 11, 2015 at 8:31
  • .val() works. Thanks! – ZSMJ Commented May 11, 2015 at 8:35
  • despite the official documentation talks about "button.js" (getbootstrap./javascript) I would rather remend use to use some pure jQuery solutions for such problems, it is just enough ;) – briosheje Commented May 11, 2015 at 8:36
  • 1 you will never see the word 'loading', as you're also immediately changing it to 'reset'... Perhaps you want to do something before changing it to 'reset'? – toomanyredirects Commented May 11, 2015 at 8:39
Add a ment  | 

2 Answers 2

Reset to default 1

Try this:

$('#save').click(function() {
      var btn = $(this);
      btn.val(btn.data("loading-text")); setTimeout(function() {
          btn.val('reset');
        }, 2000);
      });
<script src="https://ajax.googleapis./ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="submit" data-loading-text="Loading..." style="" id="save" class="btn btn-primary " value="Submit" name="save">

Here's an example, you need to btn.val('loading...'); because you change the value of your input. Here's a working demo.

本文标签: javascriptdataloadingtext not workingStack Overflow