简体   繁体   English

更改引导加载按钮文本

[英]change bootstrap loading button text

I've been trying to get a loading button going where a bootstrap refresh glyphicon keeps rotating until the server has responded to my request. 我一直在尝试使加载按钮转到引导刷新glyphicon不断旋转的位置,直到服务器响应我的请求为止。 This is the button: 这是按钮:

<button type="submit" id="loading" name="loading" class="btn btn-lg btn-default" 
onclick="change()" style="margin-top:40px; margin-bottom:25px;">
span id="state"></span>Submit</button>

When i click the button, the glyphicon to the left of the button starts rotating, that part is working so far. 当我单击按钮时,按钮左侧的glyphicon开始旋转,到目前为止该部分已经开始工作。 The text to the right of the button (now: Submit) needs to change to "Loading". 按钮右侧的文本(现在为:提交)需要更改为“正在加载”。 So far I've got the following script: 到目前为止,我有以下脚本:

<script type="text/javascript">
    function submit() {
        document.getElementById("loading").click();
    }
    function change() { 
        var mybutton = document.getElementById("loading");
        var mystring1 = document.getElementById("input_ipaddress").value;
        var mystring2 = document.getElementById("input_hostname").value;
        var mystring3 = document.getElementById("input_comms").value;
        if (mystring1 && mystring2 && mystring3) {
            document.getElementById("state").className = "glyphicon glyphicon-refresh glyphicon-refresh-animate";   
            mybutton.innerHTML = "Loading...";
        }       
    }
    // remove all classes of the "state" span class
    window.onload = function() {
        document.getElementById('state').className = "";
    };
</script>

The CSS, if this helps resolving my issue: CSS,如果这有助于解决我的问题:

.glyphicon-refresh-animate {
-animation: spin .7s infinite linear;
-webkit-animation: spin2 .7s infinite linear;
}

@-webkit-keyframes spin2 {
from { -webkit-transform: rotate(0deg);}
to { -webkit-transform: rotate(360deg);}
}

@keyframes spin {
from { transform: scale(1) rotate(0deg);}
to { transform: scale(1) rotate(360deg);}
}

I've been trying innerHTML, but that of course replaces everything (including the glyphicon) with given text. 我一直在尝试innerHTML,但是那当然用给定的文本替换了所有内容(包括glyphicon)。 How can i solve this? 我该如何解决?

Problem is your new text Loading.. is overlapping glyphicon . 问题是您的新文本Loading..glyphicon重叠。

Try this: 尝试这个:

mybutton.innerHTML = '<span id="state"></span>Loading..'

You can also use; 您也可以使用;

<button type="button" class="btn btn-primary btn-lg" 
   data-loading-text="<i class='fa fa-spinner fa-spin'></i> Processing">
   <i class="fa fa-arrow-down"></i>&nbsp;Download
</button>

$('.btn').on('click', function() {
   var $this = $(this);
   $this.button('loading');
   setTimeout(function() {
      $this.button('reset');
   }, 8000);
});

Source: @ codepen 资料来源:@ Codepen

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM