功能展示:
1.點選按鈕,
2.開始倒數計時
3.到1後還原為60
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>60秒倒數計時</title>
</head>
<body>
<input id="get_pass" type="button" value="獲取驗證碼" onClick="click1()">
</body>
</html>
<script language="javascript">
var j = function () {
return document.getElementById("get_pass");
};
var number = 60;
function click1() {
j("get_pass").value = number + "秒";
number = number - 1;
//當計數為0的時候,還原內容 並將number=60
if (number < 0) {
j("get_pass").removeAttribute("disabled");
j("get_pass").value = "獲取驗證碼";
number = 60; //將number還原成60
} else {
j("get_pass").setAttribute("disabled", false);
setTimeout("click1()", 1000);
}
}
</script>複製程式碼