小編給大家分享一下js如何實現簡單的獲取驗證碼按鈕效果,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
效果圖:

圖(1)初始圖

圖(2)點擊后
代碼如下:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8" />
<title>pro.html</title>
<style type="text/css">
.checkCode {
cursor: pointer;
border: 1px solid black;
text-align: center;
line-height: 26px;
width: 115px;
height: 35px;
}
</style>
<script type="text/javascript">
var sleep = 30, interval = null;
window.onload = function ()
{
var btn = document.getElementById ('btn');
btn.onclick = function ()
{
if (!interval)
{
this.style.backgroundColor = 'rgb(243, 182, 182)';
this.disabled = "disabled";
this.style.cursor = "wait";
this.value = "重新發送 (" + sleep-- + ")";
interval = setInterval (function ()
{
if (sleep == 0)
{
if (!!interval)
{
clearInterval (interval);
interval = null;
sleep = 30;
btn.style.cursor = "pointer";
btn.removeAttribute ('disabled');
btn.value = "免費獲取驗證碼";
btn.style.backgroundColor = '';
}
return false;
}
btn.value = "重新發送 (" + sleep-- + ")";
}, 1000);
}
}
}
</script>
</head>
<body>
<input class="checkCode" type="button" id="btn" value="免費獲取驗證碼" />
</body>
</html>看完了這篇文章,相信你對“js如何實現簡單的獲取驗證碼按鈕效果”有了一定的了解,如果想了解更多相關知識,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。