document.getElementById("yan").onclick=function(){time(this);} 这句让你不会去执行后台方法可以这样写
OnClientClick="time()" OnClick="yan_onClick" 

解决方案 »

  1.   

    服务器端的空间ID在生成HTML标签时ID可能不是“yan”,你查看下源代码
      

  2.   


    <script type="text/javascript">
                    var wait=45;
                    document.getElementById("yan").disabled = false;   
                    function time(o) {
                            if (wait == 0) {
                                o.removeAttribute("disabled");           
                                o.value="获取验证码";
                                wait = 5;
                            } else {
                                o.setAttribute("disabled", true);
                                o.value="重新发送(" + wait + ")";
                                wait--;
                                setTimeout(function() {
                                    time(o)
                                },
                                1000)
                            }
                        }
                    onclick=function(){time(this);}
                    </script> js这样写么?这样好像是执行了后台的方法。不过没倒计时的效果了?
      

  3.   


    <script type="text/javascript">
                    var wait=45;
                    document.getElementById("yan").disabled = false;   
                    function time(o) {
                            if (wait == 0) {
                                o.removeAttribute("disabled");           
                                o.value="获取验证码";
                                wait = 5;
                            } else {
                                o.setAttribute("disabled", true);
                                o.value="重新发送(" + wait + ")";
                                wait--;
                                setTimeout(function() {
                                    time(o)
                                },
                                1000)
                            }
                        }
                    onclick=function(){time(this);}
                    </script> js这样写么?这样好像是执行了后台的方法。不过没倒计时的效果了?我的意思是这样:
     <script type="text/javascript">
                    var wait=45;
                    document.getElementById("yan").disabled = false;   
                    function time(o) {
                            if (wait == 0) {
                                o.removeAttribute("disabled");           
                                o.value="免费获取验证码";
                                wait = 5;
                            } else {
                                o.setAttribute("disabled", true);
                                o.value="重新发送(" + wait + ")";
                                wait--;
                                setTimeout(function() {
                                    time(o)
                                },
                                1000)
                            }
                        }
               
                    </script> <asp:Button runat=server CssClass="enter" Text="获取验证码" ID="yan" name="yan"  OnClientClick="time(this)" OnClick="yan_onClick" style="width:40%;" />
                   
    tiem(this)  这个this 是传的button  不知道你想传什么。 可以自己改下
      

  4.   

    也是学习了一番   这个或许对你有帮助  正解   http://bbs.csdn.net/topics/390438427