求大神指導,在火狐里有BUG
<!DOCTYPE?html> <html> ????<head> ????????<meta?charset="UTF-8"> ????????<title>發(fā)送驗證碼練習</title> ????<style?type="text/css"> ????????.nosend{width:?120px;height:?50px;background-color:?#999999;color:?#FFFFFF;margin:?30px?400px;} ????????.send{width:?120px;height:?50px;background-color:?#0C4E7C;color:?#FFFFFF;margin:?30px?400px;} ????</style> ????</head> ????<body> ????????<input?type="button"?id="send"?value="發(fā)送驗證碼"?class="send"/> ????</body> ????<script?type="text/javascript"> ????????var?mybtn=document.getElementById("send"); ????????var?timer=null; ????????var?index=10; ????????mybtn.onclick=function(){ ????????????if(timer){clearInterval(timer);timer=null;} ????????????mybtn.setAttribute("disabled","disabled"); ????????????mybtn.setAttribute("class","nosend"); ????????????timer=setInterval(function(){ ?????????????index--; ?????????????mybtn.value=index+"后重新發(fā)送"; ?????????????if(index<0){ ?????????????????clearInterval(timer); ?????????????????mybtn.removeAttribute("disabled"); ?????????????????mybtn.setAttribute("class","send"); ?????????????????mybtn.value="重新發(fā)送驗證碼"; ?????????????????index=10; ?????????????} ????????????},1000); ????????} ????</script> </html>
這是完整代碼,有一個BUG,在火狐瀏覽器里第一次運行正常,當刷新頁面的時候會自動加上一個disabled屬性,而在谷歌瀏覽器里就正常,這是為什么呢?
還有,提示里的disabled屬性設置為‘true’或‘false’好像并不管用。
2016-10-06
window.onload=function(){
? ?var send=document.getElementById('send'),
? ? ? ?times=60,
? ? ? ?timer=null;
? ?send.onclick=function(){
???? ? ? timer=setInterval(function(){
???????? ? ? times--;
???????? ? ? if(times<=0){
???????? ? ? send.value="發(fā)送驗證碼"
???????? ? ? clearInterval(timer);
???????? ? ? send.disabled=""
???????? ? ? times=60;
???????? ? ? }else{
???????? ? ? send.value=times+"秒后重試";
???????? ? ? send.disabled="disabled"
???????? ? ? }
???? ? ? },1000)
? ? ?// 計時開始?
? ?}?
}
自認為代碼很簡單,你試試,
2016-05-18
看不懂