在提交时更改按钮颜色,直到输入新文本

时间:2016-04-10 12:43:53

标签: javascript

是否可以在提交按钮时更改按钮的颜色一段时间,直到整个过程再次开始?

2 个答案:

答案 0 :(得分:0)

试试这个

document.getElementById('send_btn').style["background-color"]="red"
setTimeout(function() {
  document.getElementById('send_btn').style["background-color"] = ""
}, 1000) // 1000 - This value is in ms. (here time is 1second)

答案 1 :(得分:0)

只需将element.style.backgroundColor = "color";放在流程的不同步骤上即可。例如:



function steps() {

  var button = document.getElementById("btn");

  button.style.backgroundColor = "orange";  

  setTimeout(function(){ button.innerHTML = "1"; }, 1000);

  setTimeout(function(){ button.innerHTML = "2"; }, 2000);

  setTimeout(function(){ button.innerHTML = "3"; }, 3000);

  setTimeout(function(){ button.style.backgroundColor = "tomato"; }, 4000);

  setTimeout(function(){  
    button.innerHTML = "click here";
    button.style.backgroundColor = "skyblue"; }, 6000);  

}

button {
  width: 100px;
  padding: 15px;
  background: skyblue;  
}

<button id=btn onclick="steps()">click here</button>
&#13;
&#13;
&#13;