// Press enter in the gridview text box to trigger the Button event
<Script type = "text/javascript" language = "javascript">
Function clickButton ()
{
If (event. keyCode = 13)
{
Document. all ('ibtnupdate'). click ();
Return false;
}
}
</Script>
<Asp: TextBox ID = "TextBox3" onkeypress = "return (clickButton ();" runat = "server">
<Script type = "text/javascript" language = "javascript">
Function KeyDown () // block the carriage return event
{
If (event. keyCode = 13)
{
Return false;
}
}
Function EnterTextBox () // press enter in the final text box to trigger submission
{
If (event. keyCode = 13 & document. all ["txtCode"]. value! = "")
{
Document. all ['btnup']. focus ();
Document. all ['btnup']. click ();
Return false;
}
}
</Script>
<Form id = "form1" runat = "server" onkeypress = "return KeyDown ()"> // block the carriage return event
This.txt Code. Attributes. Add ("onkeypress", "EnterTextBox ()"); // press enter in the final text box to trigger submission
/*
1. If there is a type = "submit" button in the form, the Enter key takes effect.
2. If there is only one input of type = "text" in the form, no matter what type the button is, the Enter key takes effect.
3. If a button uses a button instead of input, and no type is added, type = button is used by default in IE, and type = submit is used by default in FX.
4. Other form elements, such as textarea and select, do not affect the trigger rule. radio checkbox does not affect the trigger rule. However, in FX, the Return key is returned and the response is not returned in IE.
5. The input of type = "image" has the same effect as type = "submit". I don't know why such a type is designed. It is not recommended, you should use CSS to add a background image.
In actual application, it is easy to make the form respond to the carriage return key, and ensure that there is a type = "submit" button in the form. What if there is only one text box that does not want to respond to the Enter key? My method is a bit awkward, that is, to write another meaningless text box and hide it. According to the 3rd rules, we try to explicitly declare the type when using the button to make the browser consistent.
*/
// Be sure to add return
// The background event is executed only when the verification is passed.
BtnLogin. Attributes. Add ("onclick", "return checkLoginForm ();");
Author "xueinsz"