主要使用到JS的:
1、disabled=true|false;
disabled的属性设置或返回是否禁用单选按钮。true为禁用。
如果想取消时使用:
document.getElementById(“text_id”).disabled=”false”;不会起作用。
正确写法为:document.getElementById(“text_id”).disabled=false;去掉引号或者:document.getElementById(“text_id”).disabled=”“;设置为空即可。
2、removeAttribute(‘disabled’);
移除/删除指定的属性。
removeProperty与removeAttribute的区别是:
removeProperty:符合w3c的(gecko,opera,webkit)的使用
removeAttribute:IE的使用
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>验证码倒计时发送</title>
<script type="text/javascript">
window.onload=function(){
var send=document.getElementById('send'),
times=5,//倒计时时间
timer=null;
send.onclick=function(){
// 计时开始
timer=setInterval(function (){
send.value=times+"秒后重试";
times--;
send.disabled=true;//让input标签不可用
if(times<0){
clearInterval(timer);
send.value="发送验证码";
times=5;
send.removeAttribute('disabled');//移除disabled属性
}
}, 1000);
}
}
</script>
</head>
<body>
<input type="button" id="send" value="发送验证码">
</body>
</html>