回车键登录系统
页面文件:
View Code
1 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="回车键登录.aspx.cs" Inherits="回车键登录" %> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 3 <html xmlns="http://www.w3.org/1999/xhtml"> 4 <head runat="server"> 5 <title></title> 6 <script type="text/javascript"> 7 function enterkey() { 8 try { 9 //var el_keydown = window.event.srcElement; 10 obj = window.event.srcElement ? window.event.srcElement : window.event.target;//兼容firefox 11 if (event.keyCode == 13 && obj.id == "username") { 12 13 document.getElementById("password").focus(); 14 return false; 15 } 16 else if (event.keyCode == 13 && obj.id == "password") { 17 document.getElementById("login").focus(); 18 } 19 } 20 catch (e) { 21 return; 22 } 23 } 24 </script> 25 </head> 26 <body> 27 <form id="form1" runat="server"> 28 <asp:TextBox ID="username" runat="server" onkeydown="return enterkey()"></asp:TextBox><br /> 29 <asp:TextBox ID="password" runat="server" onkeydown="enterkey()"></asp:TextBox><br /> 30 <asp:Button ID="login" runat="server" Text="登录" OnClick="login_Click" /> 31 </form> 32 </body> 33 </html>
cs文件:
View Code
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Web; 5 using System.Web.UI; 6 using System.Web.UI.WebControls; 7 8 public partial class 回车键登录 : System.Web.UI.Page 9 { 10 protected void Page_Load(object sender, EventArgs e) 11 { 12 13 } 14 protected void login_Click(object sender, EventArgs e) 15 { 16 Response.Write("登录成功!"); 17 } 18 }