动态设置默认按钮

<script type="text/javascript">
     document.onkeydown=xx;
     function xx()
     {
         var se = event.srcElement;
         if(event.keyCode==13)
         { 
             if(se.id=="textBox1")
             {
             document.getElementById("button1").focus();
             document.getElementById("button1").click();
             }
             if(se.id=="textBox2")
             {
              document.getElementById("button2").focus();
              document.getElementById("button2").click();
             }
         }
     }
    
</script>

<form id="form1" runat="server">
        <div>
            <table width="100%" cellpadding="2" cellspacing="2" border="1">
                <tr>
                    <td>
                        <asp:TextBox ID="textBox1" runat="server"></asp:TextBox></td>
                    <td>
                        <asp:TextBox ID="textBox2" runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td>
                        <asp:Button ID="button1" runat="server" Text="button1" OnClick="button1_Click"></asp:Button></td>
                    <td>
                        <asp:Button ID="button2" runat="server" Text="button2" OnClick="button2_Click"></asp:Button></td>
                </tr>
            </table>
        </div>
    </form>

你可能感兴趣的:(动态设置默认按钮)