怎么设置回车键触发某个button按钮

解决方案 »

  1.   


     <script language="javascript">        function SubmitKeyClick()        {               if (event.keyCode == 13)             {                     event.keyCode=9;              event.returnValue = false;              document.all('button1').click();            }}
    </script>
      

  2.   

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
        <script>
        function cli()
        {
            location.href="http://www.sina.com";
        }
        
        function bin()
        {
             if (event.keyCode == 13)
             {
                document.getElementById('Button1').click();
             }
        }
        </script>
        
    </head>
    <body onkeydown="bin()">
        <form id="form1" runat="server">
        <div>
            <input id="Button1" type="button" value="button" onclick="cli()" /></div>
        </form>
    </body>
    </html>
      

  3.   

    在你的代码文件中Page_Load()事件里加上这段代码:
    假设你页面的form的id为fm,button的id为btn  
       
      protected   HtmlForm   fm;
      string   ref=Page.GetPostBackEventReference(btn);  
      fm.Attributes.Add("onkeydown","if(event.keyCode==13){if(PageValidate(){"+ref+";}}");