按下输入键时,按钮单击事件在文本框内(在Web中)

按下输入键时,按钮单击事件在文本框内(在Web中)

问题描述:

如何触发按钮在文本框中写入一些文本后按Enter键时单击事件。



How to Fire Button Click Event when Enter key is pressed after writing some text in textbox.

<form id="form1"  runat="server">
    <div>
    
    Enter text-<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Send" Width="65px" />
    
    </div>
    </form>

试试这个

$ b



函数enterEvent(e){

if(e.keyCode == 13){
Try this



function enterEvent(e) {
if (e.keyCode == 13) {


(input [id = Button1])。click();

}

}



< asp:textbox id =TextBox1onkeydown =javascript:enterEvent(event); runat =serverxmlns:asp =#unknown>



< asp:button id =Button1runat =servertext =Button onclick =Button1_Clickxmlns:asp =#unknown>
("input[id=Button1]").click();
}
}

<asp:textbox id="TextBox1" onkeydown="javascript:enterEvent(event);" runat="server" xmlns:asp="#unknown">

<asp:button id="Button1" runat="server" text="Button" onclick="Button1_Click" xmlns:asp="#unknown">


将所有页面包含在面板中并将 DefaultButton 属性设置为提交按钮。

Take all your page contains in a panel and set DefaultButton property to your submit button.
<asp:panel runat="server" id="pnlSrchQuote" defaultbutton="btnSearch" xmlns:asp="#unknown">
     <!--My Controls here-->
</asp:panel>





--Amit



--Amit