我现在要做发送手机验证码的按钮,要求是点击按钮后一分钟内不可用(防止用户反复发送),一分钟后按钮变为可用状态。<input type="button" name="sendsms" value="${literal['jsp.mobileverify.003']}" 
onclick="setTimeout((function(Mes){Mes.disabled=true;return function(){Mes.disabled=false;};})(this),5000);         
location.href='${pageContext.request.contextPath}/app/trialset/mobile_auth/sendsms';" />我是这样写的,但是因为后面的location.href=''    这是个Action的地址,要刷新页面的。所以前面的
setTimeout脚本就失效了请问我该如何解决最好给贴个代码。谢谢!!!!

解决方案 »

  1.   

    <a 
    target='_blank'
    onclick="setTimeout((function(Mes){Mes.disabled=true;return function(){Mes.disabled=false;};})(this),5000);   
    this.href='${pageContext.request.contextPath}/app/trialset/mobile_auth/sendsms';" >
    ${literal['jsp.mobileverify.003']}
    </a>
      

  2.   

    location.href='' 里传个参数过去 在onload的时候判断 如果存在这个参数 就让按钮一分钟内不可用
      

  3.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <script type="text/javascript">
    function validate(){
    var st = window.location.hash;
    var sts = st.split("#");
    if(sts.length>1){
    var btn = document.getElementById("btn_ok");
    btn.disabled=true;
    window.setTimeout(function(){
    btn.disabled = false;
    },1000*2);
    window.location.hash="";
    }
    }
    function submit(){
    window.location.hash = window.location.hash+"#123";
    window.location.reload();
    }
    </script>
    </head>
    <body onload="validate()">
    <input type="button" id="btn_ok" onclick="submit()" value="提交"/>
    </body>
    </html>