JQuery implements carriage return instead of the Tab key (Press enter to jump to the next column), jquerytab

Source: Internet
Author: User

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.

  1. $ (Function (){
  2. $ ("Form [name = 'tractform'] input: text"). keypress (function (e ){
  3. If (e. which = 13) {// determines whether the return key is pressed.
  4. Var inputs = $ ("form [name = 'tractform']"). find (": text"); // obtain all input boxes in the form
  5. Var idx = inputs. index (this); // obtain the position of the current focus input box
  6. If (idx = inputs. length-1) {// determines if it is the last input box
  7. If (confirm ("the last input box has been input. Are you sure you want to submit it? ") // User confirmation
  8. $ ("Form [name = 'tractform']"). submit (); // submit the form
  9. } Else {
  10. Inputs [idx + 1]. focus (); // sets the focus
  11. Inputs [idx + 1]. select (); // select text
  12. }
  13. Return false; // cancel the default submission Behavior
  14. }
  15. });
  16. });

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>

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.