When a large amount of content is added to a webpage, You need to press enter to replace the Tab key and enter the content in order.
In asp.net, The fouce function has functions, which are both control focus. However, to replace the Tab key with carriage return, you must use a scripting language.
In fact, the principle is very simple. In the page event, the detection window. event. keyCode is 13 (both the key value of the carriage return), with 9 (both the key value of the Tab key ).
<Script language = "JavaScript" type = "text/javascript">
<! --
Specified parameter Doc ument. attachEvent ("onkeydown", function (){
If (window. event. keyCode = 13 ){
Window. event. keyCode = 9;
}
});
// -->
</Script>
Of course, to make the controls on the asp.net page "Tab" in a certain order, you must set the TabIndex values of these controls in the order you need.
<Asp: TextBox ID = "TextBox1" runat = "server" AutoCompleteType = "Department" TabIndex = "1"> </asp: TextBox> <br/>
<Asp: TextBox ID = "TextBox2" runat = "server" TabIndex = "2"> </asp: TextBox> <br/>
<Asp: TextBox ID = "TextBox3" runat = "server" TabIndex = "3"> </asp: TextBox>
<Br/>
<Asp: TextBox ID = "TextBox4" runat = "server" TabIndex = "4"> </asp: TextBox> <br/>
<Asp: TextBox ID = "TextBox5" runat = "server" TabIndex = "5"> </asp: TextBox> <br/>
<Asp: Button ID = "Button1" runat = "server" Text = "Button"/> </div>
In this example, only press enter to replace the Tab key, but when you really need to press enter, you can only click the button with the mouse. I want to implement a more ideal solution. When all the text boxes have been filled in, and the focus (Tab) arrives at the submit button, press enter to submit them directly, if anyone can implement this idea, please leave a message here. I am very grateful!
The Code is as follows:
<% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Default3.aspx. cs" Inherits = "Default3" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> No title page </title>
<Script language = "JavaScript" type = "text/javascript">
<! --
Specified parameter Doc ument. attachEvent ("onkeydown", function (){
If (window. event. keyCode = 13 ){
Window. event. keyCode = 9;
}
});
// -->
</Script>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
<Asp: TextBox ID = "TextBox1" runat = "server" AutoCompleteType = "Department" TabIndex = "1"> </asp: TextBox> <br/>
<Asp: TextBox ID = "TextBox2" runat = "server" TabIndex = "2"> </asp: TextBox> <br/>
<Asp: TextBox ID = "TextBox3" runat = "server" TabIndex = "3"> </asp: TextBox>
<Br/>
<Asp: TextBox ID = "TextBox4" runat = "server" TabIndex = "4"> </asp: TextBox> <br/>
<Asp: TextBox ID = "TextBox5" runat = "server" TabIndex = "5"> </asp: TextBox> <br/>
<Asp: Button ID = "Button1" runat = "server" Text = "Button"/> </div>
</Form>
</Body>
</Html