更改引导加载按钮文本
问题描述:
我一直在试图让一个加载按钮去引导刷新图形不断旋转,直到服务器响应我的请求。这是按钮:更改引导加载按钮文本
<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>
当我点击该按钮,glyphicon到按钮的左边开始旋转,部分工作至今。该按钮右侧的文本(现在:提交)需要更改为“正在加载”。到目前为止,我有以下脚本:
<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>
的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);}
}
我一直很努力的innerHTML,但当然一切替换(包括字形)与给定的文本。我该如何解决这个问题?
你为什么要使用纯JS?为什么你不能使用jQuery? – 2014-09-12 12:18:18
为什么不直接使用内置的Bootstrap方式呢? http://getbootstrap.com/javascript/#buttons – gpgekko 2014-09-12 12:19:30
代码似乎很好,按钮文本应该改变。问题在别的地方。 – Manwal 2014-09-12 12:23:38