JQuery implements carriage return instead of the Tab key (Press enter to jump to the next column), jquerytab
After a button is submitted, if you press the Enter key on the keyboard, this form will be submitted by default. In this way, the user experience is poor for entering various forms of projects. after entering a project, you can select the next project with the mouse or press the Tab key on the keyboard to select the next project.
Ii. Problem requirements:
1: if the current focus (that is, the text box that the user is entering) is not the last input box, press enter to move the focus to the next input box;
2: If the current focus (that is, the text box that the user is entering) is the last input box, press the Enter key and ask the user to confirm and submit the form;
3. Basic Ideas:
1: It is easy to judge whether the key is created by pressing enter. With the event in jQeury, you can get the value of the currently pressed key. The value of the Return key is 13. Just compare it.
2: Check whether the input box in the current focus is the last one.
- $ (Function (){
- $ ("Form [name = 'tractform'] input: text"). keypress (function (e ){
- If (e. which = 13) {// determines whether the return key is pressed.
- Var inputs = $ ("form [name = 'tractform']"). find (": text"); // obtain all input boxes in the form
- Var idx = inputs. index (this); // obtain the position of the current focus input box
- If (idx = inputs. length-1) {// determines if it is the last input box
- If (confirm ("the last input box has been input. Are you sure you want to submit it? ") // User confirmation
- $ ("Form [name = 'tractform']"). submit (); // submit the form
- } Else {
- Inputs [idx + 1]. focus (); // sets the focus
- Inputs [idx + 1]. select (); // select text
- }
- Return false; // cancel the default submission Behavior
- }
- });
- });
Jquery press enter to convert to the tab key
This is probably the only thing we can do. jquery events are packaged.
$ (Function (){
$ ("Body"). live ("keydown", function (){
Window. event. keyCode = 9
})
})
Javascript/jquery data input can be switched to the next row by pressing the tab key once. How can this problem be achieved?
<Html xmlns = "www.w3.org/5o/xhtml" lang = "zh-CN">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> tabindex </title>
<Style type = "text/css">
</Style>
<Script type = text/javascript>
</Script>
</Head>
<Body>
<Table>
<Tr>
<Td> <input type = "text" tabindex = "101"/> </td>
<Td> <input type = "text"/> </td>
<Td> <input type = "text"/> </td>
</Tr>
<Tr>
<Td> <input type = "text" tabindex = "102"/> </td>
<Td> <input type = "text"/> </td>
<Td> <input type = "text"/> </td>
</Tr>
<Tr>
<Td> <input type = "text" tabindex = "103"/> </td>
<Td> <input type = "text"/> </td>
<Td> <input type = "text"/> </td>
</Tr>
</Table>
</Body>