默认情况下如何在textxbox上调用按钮单击事件 [英] how to call button click event by default on textxbox

查看:66
本文介绍了默认情况下如何在textxbox上调用按钮单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有两个文本框和两个按钮
现在,如果我在第一个文本框中输入一些文本,然后按Enter键,则第一个按钮将触发.
如果我在第二个文本框中输入一些文本,然后按Enter键,则第一个按钮被触发,但我想触发第二个按钮.

请让我知道如何实现它.

谢谢你
mohd wasif

Hi,

I have two textboxes and two button
Now if i enter some text in first textbox and press enter key then first button is firing.
if i enter some text in second textbox and press enter key then first button is firing but I want to fire second button.

Please let me know how to implement it.

Thanking you
mohd wasif

推荐答案

您可以这样做
You can do like that
function button1()
{
    document.getElementById(''<%= Button1.ClientID%>'').focus()
}
function button2()
{
    document.getElementById(''<%= Button2.ClientID%>'').focus()
}


并在文本框的"onblur"事件上调用这些函数,例如


and call these functions on "onblur" event of the textbox like

<asp:textbox id="TextBox1" runat="server" onblur="button1()" xmlns:asp="#unknown" />


编写JavaScript函数并处理文本框的keyup事件.检查KeyCode是否为13(即按下输入按钮),调用相应的按钮单击事件.

尝试一下!
Write a JavaScript function and handle the keyup event of the textbox. Check if the KeyCode is 13 (i.e) enter button is pressed, call the corresponding button click event.

Give it a try!


如果要在文本框中按Enter,请参见下文-vb.net

假设button2具有您要调用的代码-通过在文本框中按Enter键

这是一种简单的方法

公告-Textbox1_keydown
If you want to press enter in a textbox - see below - vb.net

Let''s say that button2 has the code you want to call - by pressing enter in a textbox

This is an easy way to do it

notice - Textbox1_keydown
Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
   If (e.KeyCode = Keys.Enter) Then Button2.PerformClick()
End Sub


这篇关于默认情况下如何在textxbox上调用按钮单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆