textbox 回车的问题

ref:

http://blog.sina.com.cn/s/blog_4b1a1001010007zf.html

http://hi.baidu.com/trip008/blog/item/80b56aa7a09c0b91d0435821.html

 

 

前台:
function GetFocus()
{
    if(event.keyCode==13)
    {
        document.getElementById("Button1").click();
        return false;
    }
}

后台:
TextBox1.Attributes.Add("onkeydown","return GetFocus();");

或者:
<SCRIPT LANGUAGE="javascript">
      function SubmitKeyClick(button)
      {
            if (event.keyCode == 13)
            {
                  if(event.srcElement.id=="tbInput")
                  {
                        event.keyCode=9;
                        event.returnValue = false;
                        document.all[button].click();
                  }
            }
      }
// -->
</SCRIPT>

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1、将页面上所有回车事件都绑定到一个按钮上
<HEAD>
  <script language="javascript">
  function EnterTextBox()
  {
    if(event.keyCode == 13 && document.all["TextBox1"].value != "")
    {
      event.keyCode = 9;
      event.returnValue = false;
      document.all["Button1"].click();
    }
  }
  </script>
</HEAD>
<body onkeypress="return EnterTextBox()">
 
2.不同的TextBox绑定不同的Button
<HEAD>
  <script language="javascript">
  function EnterTextBox(button)
  {
    if(event.keyCode == 13)
    {
      event.keyCode = 9;
      event.returnValue = false;
      document.all[button].click();
    }
  }
  </script>
  </HEAD>
 
在对应的cs文件中
//绑定TextBox回车事件
TextBoxPortOfDestination .Attributes.Add("onkeypress", "EnterTextBox('ButtonChoose')");
TextBoxItemName.Attributes.Add("onkeypress","EnterTextBox('ButtonAdd')");
TextBoxCost_PX.Attributes.Add("onkeypress","EnterTextBox('ButtonAdd')");
TextBoxCost_1X20.Attributes.Add("onkeypress","EnterTextBox('ButtonAdd')"); 

 

 

 

asp.net的TextBox回车触发事件
2008-03-13 16:11

// 直接在js中写
< script language = " javascript " >
     function EnterTextBox()
   
{
         
if ( event .keyCode == 13 && document.all[ " TextBox1 " ].value != "" )
           {
             
event .keyCode = 9 ;
             
event .returnValue = false ;
              document.all[
" TextBox1 " ].click();
          }

     }

   
</ script >

< body onkeypress = " return EnterTextBox() " >
// 此处TextBox1为页面上TextBox的ID


二.
<script language="javascript">
     function EnterTextBox(button)
      {
         
if(event.keyCode == 13 && document.all["TextBox1"].value != "")
            {
             
event.keyCode = 9;
             
event.returnValue = false;
              document.all[button].click();
          }

     }
   
</script>

在PageLoad事件里
TextBox1.Attribute.add(
"onkeypress","EnterTextBox('Button1')");

你可能感兴趣的:(text)