zoukankan      html  css  js  c++  java
  • asp.net textbox回车变成按扭事件

    1.
    C# code

    private void txt_KeyPress(object sender, KeyPressEventArgs e)
    {
    btnfind_Click(
    this, null);
    }

    2.

    JScript code
    function keyDown(str1){
    if(event.keyCode==13)
    {
    var a;
    a
    =str1;
    eval(
    "window.document.Form1."+a+".focus();");
    }
    }

    HTML code
    <div id="div_search">关键字:<asp:textbox id="keyword" onkeydown="keyDown('btnsearch');" Width="180px" Runat="server"></asp:textbox>&nbsp;
    <asp:button id="btnsearch" Runat="server" Text="搜索"></asp:button></div>


    3.如果你的页面中没有太多的自定义功能的话,用个简单的方法解决吧:
    给 <form>添加一个属性:defaultbutton="YourButtonID"

    4.

    <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>

    <asp:TextBox ID="txt1"  runat="server"> </asp:TextBox>
    <asp:Button ID="'Button1'" runat="server" Text="Button1" />
    在page_load 事件中加入
    TextBox1.Attribute.add("onkeypress","EnterTextBox('Button1')");

    5.因为form中的input的默认事件是提交表单,所以要阻止默认事件。
    兼容的写法为:
      function stopDefault( e ) {
          if ( e && e.preventDefault )
              e.preventDefault();
          else
              window.event.returnValue = false;
          return false;
      }

  • 相关阅读:
    b站尚硅谷MySQL笔记(婷姐初级,周阳高级)
    word--公式添加编号
    excel--长数字显示问题
    R语言--蒙特卡洛计算定积分
    数学
    数学
    Computer Science
    Computer Science
    Computer Science
    元学习
  • 原文地址:https://www.cnblogs.com/blsong/p/1609591.html
Copyright © 2011-2022 走看看