zoukankan      html  css  js  c++  java
  • asp.net中如何回车触发指定按钮的事件

    问题内容:
    在asp.Net中,如何回车触发指定按钮的事件?
    假设:
    <asp:TextBox id="tbInput" runat="server" Width="240px"></asp:TextBox>
    <asp:Button id="btnOK" runat="server" BorderWidth="1px" BorderColor="Purple" BorderStyle="Solid" Text="Search Site"></asp:Button>
    -----------------------------------------------------------------------------------------------------------------------------

    方法一:

    直接 TextBox1.Attributes.Add("onkeydown", "if(event.keyCode==13){document.all.Button3.focus();document.all.Button3.click();}");

    -----------------------------------------------------------------------------------------------------------------------------

    方法二: (这个方法解决了我项目的问题)

    在.aspx页面中添加:
    <SCRIPT LANGUAGE="Javascript">
    function SubmitKeyClick(button)
    {   
     if (event.keyCode == 13)
     {       
      event.keyCode=9;
      event.returnValue = false;
      document.all[button].click();
     }
    }
    // -->
    </SCRIPT>

    在Page_Load事件中添加:
    txtPwd.Attributes.Add("onkeydown", "SubmitKeyClick('"+ImageButton1.ClientID+"');");

  • 相关阅读:
    序列操作
    上帝造题的七分钟2 / 花神游历各国
    火柴排队
    pair(对组)用法
    线段树
    链上分治
    Rem与Px的转换
    css中单位px和em,rem的区别
    css网页自适应-1
    css网页自适应-2
  • 原文地址:https://www.cnblogs.com/SALIN/p/1279699.html
Copyright © 2011-2022 走看看