#region 给文本框添加回车事件
    private void InitCountrol()
    {
        this.TxtName.Attributes["onkeydown"] = "if(event.keyCode == 13){event.keyCode = 9;" + ClientScript.GetPostBackClientHyperlink(BtnOK, "") + "}";
        this.TxtPwd.Attributes["onkeydown"] = "if(event.keyCode == 13){event.keyCode = 9;" + ClientScript.GetPostBackClientHyperlink(BtnOK, "") + "}";
    }
    #endregion仅供参考。

解决方案 »

  1.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title>Untitled Page</title>
    </head>
    <body>
    用 户 名<input type=text id="user" onmousemove="login.focus();"/>
    <input type=button id="login" value="登录"  />
    关 键 字<input type=text id="keyword" onmousemove="search.focus();"/>
    <input type=button id="search" value="搜索" /></body>
    </html>
      

  2.   

    針對1樓的問題:function document.onkeypress()
    {
       if(event.keyCode==13)
       {
          if(event.srcElement.id=="txtUserID")
          {
             document.getElementById("btnLogin").focus();
          }
          else if(event.srcElement.id=="txtKeyWord")
          {
             document.getElementById("btnSearch").focus();
          }
       }
    }
    <input type="text" id="txtUserID" value="userID">
    <input type="button" id="btnLogin" value="Login" onclick="alert('You Are Ready Login')">
    <br>
    <input type="text" id="txtKeyWord" value="keyWord">
    <input type="button" id="btnSearch" value="Search" onclick="alert('You Are Ready Search')">==============================================
    這樣可以.