日期:2014-05-18 浏览次数:20489 次
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { TextBox1.Attributes.Add("onkeydown", "k(event)"); TextBox2.Attributes.Add("onkeydown", "k(event)"); } protected void Button1_Click(object sender, EventArgs e) { Response.Write("点击1"); } protected void Button2_Click(object sender, EventArgs e) { Response.Write("点击2"); } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title></title> <script type="text/javascript"> function k(e) { e = e || window.event; evt = window.event ? window.event.srcElement : e.target; if (e.keyCode.toString() == "13") { if (evt.id == "TextBox1") { document.getElementById("Button1").focus(); document.getElementById("Button1").click(); } else { document.getElementById("Button2").focus(); document.getElementById("Button2").click(); } } } </script> </head> <body> <form id="form1" runat="server"> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /> <asp:Button ID="Button2" runat="server" Text="Button" onclick="Button2_Click" /> </form> </body> </html>