1 <ahref= "javascript:void (0);"onclick= "Get_captcha ()"class= "btn btn-default btn6"ID= "For_captcha" >Get Verification Code</a>2 3 <Scripttype= "Text/javascript">4 5 varURL="/get-verify-code?phone_number=";6 vari;7 8 functionCount_down () {9 I=I-1;Ten $('#for_captcha'). attr ('Disabled','Disabled'); One $('#for_captcha'). HTML ('remaining'+I+'seconds.'); A if(i<=0){ - $('#for_captcha'). Removeattr ('Disabled','Disabled'); - $('#for_captcha'). HTML ('Get Verification Code'); the Window.cleartimeout (countdown); - } - Else{ - varCountdown=SetTimeout ('Count_down ()', +); + } - } + A functionGet_captcha () { at varPhone= $('#phone'). Val ();//Console.log (phone); - URL=URL+phone; - - Re= /^1\d{10}$/; - if(Re.test (phone)) { - $.post (URL,function(data) { in Console.log (date); - }). Complete (function(){ to Console.log (' Complete'); + }); - the I= -; * Count_down (); $ }Panax Notoginseng Else { - Alert ("phone number is not correct"); the return false; + } A the } + </Script>
Note
Project using bootstrap, when I wrote this script, I found a very strange phenomenon, the click on the button to get the instant button disappeared
There's a moment in Firefox and Chrome, but just a little touch of any page element or even just a F12 for an element review,
Everything's fine.
I found that when the disabled position became relative, and normally it was static but the problem was not here because of the predefined style of bootstrap
BTN Btn-default in the blink of an application the priority weight exceeds one of my defined background-color:white which causes the illusion of coverage and button disappearance, which should not have happened.
Because touching any page element, the browser recalculates, applying my definition style
I still can't find the direct reason that he covers my style, so I use Background-color first: #218e23!important; resolve this problem.
Clips Front End JS Countdown button to get verification code