CSDN博客

img 21aspnet

按下回车表示确定提交

发表于2004/10/26 19:34:00  2423人阅读

分类: Javascript

<body  onkeydown="if (event.keyCode==13) {document.all.button2.click()}">

 

 

 

 


下面的五种方法都可以帮你解决这种问题
1.<script language=
javascript>
function document.onkeydown()
{
   if (event.keyCode == 13)
   {
   
      if (event.srcElement == document.getElementById('<%=txtEmpCode.ClientID%>'))
          document.getElementById('<%=BtnQry.ClientID%>').click();
      else if (event.srcElement == document.getElementById('<%=txtDeptCode.ClientID%>'))
          document.getElementById('<%=btnSave.ClientID%>').click();

      event.cancelBubble = true;
      event.returnValue = false;
   }
}
</script>

2.
 <body onkeydown="onkey()" bgColor="#f5efd5" MS_POSITIONING="GridLayout">
<script language="javascript">
function onkey()
{
if (window.event.keyCode==13)
{
document.all["btnQry"].focus();
}
}
</script>

3.

function document.onkeydown()
{

var source=event.srcElement.id
var btnid

if (event.keyCode == 13 )
  {
  if (source=="txtEmpCode") btnid="btnQry"
  else if (source=="txtDeptCode") btnid="btnSave"
  alert(btnid);
     var btn = document.getElementById(btnid);
     if (btn != event.srcElement)
        {btn.click();
        return false;}
  }
 

}
4.

TextBox1.Attributes.Add("onkeydown", "javascript:if (event.keyCode==13) {document.all." & Button1.ClientID & ".click();return false;}")
5.
<script language="javascript"> 
 <!--
  document.onkeydown=GlobalKeyDown;
        _CMDRETURN=13;
           _CMDTAB = 9;
           _CMDDot1 = 190;
           _CMDDot2 = 110;

         function GlobalKeyDown(){
           if(window.event.keyCode == _CMDRETURN)
      {
      if(event.srcElement.type != "submit" & event.srcElement.type != "textarea" & event.srcElement.type != "button")
       {
        window.event.keyCode = _CMDTAB;
          }
      else
       {
       window.event.keyCode =_CMDRETURN;
       }
         }
       } 
           //-->
  </script>

阅读全文
0 0

相关文章推荐

img
取 消
img