zoukankan      html  css  js  c++  java
  • onkeydown事件,应用技术巧,onkeydown事件处理回车后提交表单

    源地址:http://www.java-asp.net/aspnet/200511/t_33982.html

    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>

  • 相关阅读:
    TypesScript+Webpack
    TypeScript 类型
    git操作
    kafka
    java: cannot find symbol symbol: variable log
    Angular结构型指令,模块和样式
    Angular 自定义拖拽指令
    Angular changeDetction
    Angular 依赖注入
    RXJS Observable的冷,热和Subject
  • 原文地址:https://www.cnblogs.com/zqonline/p/1529325.html
Copyright © 2011-2022 走看看