Textbox carriage return Problem

Source: Internet
Author: User

Ref:

Http://blog.sina.com.cn/s/blog_4b1a1001010007zf.html

Http://hi.baidu.com/trip008/blog/item/80b56aa7a09c0b91d0435821.html

 

 

Front-end:
Function getfocus ()
{
   If (event. keycode = 13)
   {
     Document. getelementbyid ("button1"). Click ();
     Return false;
   }
}

Background:
Textbox1.attributes. Add ("onkeydown", "Return getfocus ();");

Or:
<Script language = "JavaScript">
Function submitkeyclick (button)
{
If (event. keycode = 13)
{
If (event. srcelement. ID = "tbinput ")
{
Event. keycode = 9;
Event. returnvalue = false;
Document. All [button]. Click ();
}
}
}
// -->
</SCRIPT>

++ ++
1. bind all carriage return events on the page to a button.
<Head>
<Script language = "JavaScript">
Function entertextbox ()
{
If (event. keycode = 13 & document. All ["textbox1"]. value! = "")
{
Event. keycode = 9;
Event. returnvalue = false;
Document. All ["button1"]. Click ();
}
}
</SCRIPT>
</Head>
<Body onkeypress = "Return entertextbox ()">

2. Bind different buttons to different textbox
<Head>
<Script language = "JavaScript">
Function entertextbox (button)
{
If (event. keycode = 13)
{
Event. keycode = 9;
Event. returnvalue = false;
Document. All [button]. Click ();
}
}
</SCRIPT>
</Head>

In the corresponding CS File
// Bind the textbox carriage return event
Textboxportofdestination . Attributes. Add ("onkeypress", "entertextbox ('buttonchoose ')");
Textboxitemname. Attributes. Add ("onkeypress", "entertextbox ('buttonadd ')");
Textboxcost_px.attributes.add ("onkeypress", "entertextbox ('buttonadd ')");
Textboxcost_1x20.attributes.add ("onkeypress", "entertextbox ('buttonadd ')");

 

 

 

Asp.net textbox press ENTER trigger event

I // Write directly in JS
< Script Language = " Javascript " >
Function entertextbox ()
{
If ( Event . Keycode = 13 && Document. All [ " Textbox1 " ]. Value ! = "" )
{
Event . Keycode = 9 ;
Event . Returnvalue = False ;
Document. All [ " Textbox1 " ]. Click ();
}
}

</ Script >

< Body onkeypress = " Return entertextbox () " >
// Textbox1 is the textbox ID on the page.

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

In the pageload event
Textbox1.attribute. Add ( " Onkeypress " , " Entertextbox ('button1 ') " );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.