JSFiddle - React, Tailwind, and code Playground
HTML
<div class="container">
<form class="registform">
<div class="formgroup g1">
<input type="tel" placeholder="手机验证码" />
<button id="getCode">获取验证码</button>
</div>
</form>
</div>
CSS
button, input, select, textarea {
padding: 0;
margin: 0;
border: 0;
outline: none;
-webkit-appearance: none;
}
.container{
width: 400px;
margin:0 auto;
padding: 30px 0;
}
.container h3{
height: 40px;
line-height: 40px;
font-size: 18px;
color: #333333;
text-indent: 5px;
}
.registform input{
width: 100%;
height: 50px;
font-size: 18px;
padding-left: 15px;
border: 1px solid #aaaaaa;
-webkit-box-sizing:border-box;
box-sizing:border-box;
}
.formgroup{
position: relative;
margin-top: 20px;
}
.g1{padding-right: 100px;}
.registform .g1 input{border-right: 0;}
.g2{padding-right: 50px;border: 1px solid #aaaaaa; }
.registform .g2 input{border: 0;}
#getCode{
position: absolute;
top: 0;
right: 0;
width: 100px;
height: 50px;
font-size: 18px;
background-color: #e35437;
color: #fff;
}
#getCode[disabled]{
background-color: #B6B6B6;
}
JavaScript
var getCode = document.getElementById('getCode');
var wait = 60;
function time(btn){
if (wait===0) {
btn.removeAttribute("disabled");
btn.innerHTML = "获取验证码";
wait = 60;
}else{
btn.setAttribute("disabled",true);
btn.innerHTML = wait + "秒后重试";
wait--;
setTimeout(function(){
time(btn);
},1000);
}
}
getCode.onclick = function(){
time(this);
};