JS検証コード60秒カウントダウン

3027 ワード


    <span class="hljs-keyword">var</span> <span class="hljs-variable">$yzm</span> = document.getElementById(<span class="hljs-string">'yzmBtn'</span>),
        flag = <span class="hljs-keyword">false</span>;
    <span class="hljs-variable">$yzm</span>.onclick = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span>{</span>
        <span class="hljs-keyword">var</span> time=<span class="hljs-number">60</span>;
        <span class="hljs-keyword">var</span> h;
        <span class="hljs-keyword">if</span>(flag){
            <span class="hljs-keyword">return</span> <span class="hljs-keyword">false</span>;
        }
        flag = <span class="hljs-keyword">true</span>;
        h= setInterval(<span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span>{</span>
            <span class="hljs-variable">$yzm</span>.style.backgroundColor=<span class="hljs-string">'#eee'</span>;
            <span class="hljs-variable">$yzm</span>.style.border=<span class="hljs-string">'1px solid #ccc'</span>;
            <span class="hljs-variable">$yzm</span>.style.color=<span class="hljs-string">'#777'</span>;
            <span class="hljs-variable">$yzm</span>.style.cursor=<span class="hljs-string">'not-allowed'</span>;
            <span class="hljs-keyword">if</span>(time<<span class="hljs-number">10</span>){
                time=<span class="hljs-string">'0'</span>+time;
            }
            <span class="hljs-variable">$yzm</span>.value=time+<span class="hljs-string">'      '</span>;
            time--;
            <span class="hljs-keyword">if</span>(time<<span class="hljs-number">0</span>){
                clearInterval(h);
                flag = <span class="hljs-keyword">false</span>;
                <span class="hljs-variable">$yzm</span>.value=<span class="hljs-string">'     '</span>;
                <span class="hljs-variable">$yzm</span>.style.backgroundColor=<span class="hljs-string">'#4DB749'</span>;
                <span class="hljs-variable">$yzm</span>.style.border=<span class="hljs-string">'none'</span>;
                <span class="hljs-variable">$yzm</span>.style.color=<span class="hljs-string">'#fff'</span>;
                <span class="hljs-variable">$yzm</span>.style.cursor=<span class="hljs-string">'pointer'</span>;
            }
        },<span class="hljs-number">1000</span>);
    }