js实现简单的获取验证码按钮效果
2019/6/27 21:07:27
本文主要是介绍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实现简单的获取验证码按钮效果的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-10-04package.json 文件位置在哪?-icode9专业技术文章分享
- 2024-10-01Craco.js学习:从入门到实践指南
- 2024-10-01Create-React-App学习:入门与实践指南
- 2024-10-01CSS-in-JS学习:从入门到实践指南
- 2024-09-30JSX语法学习:从入门到初步掌握
- 2024-09-30Mock.js学习:入门教程与实战演练
- 2024-09-30React Hooks学习:从入门到实践
- 2024-09-30受控组件学习:React中的基础入门教程
- 2024-09-29JS定时器教程:初学者必看指南
- 2024-09-29JS对象教程:初学者的全面指南