Press enter to automatically submit. Do not press enter to automatically submit.

Source: Internet
Author: User

Today, I encountered a very abnormal problem. Because a input box uses suggest, the carriage return event will be used.
However, in a form, when I press enter, my form is automatically submitted. I rely on it, but it cannot be changed.

You cannot change the submit parameter to a button. It looks like form. submit () is automatically executed ()

As a result, I got a man's article from the Internet. The original article is as follows:

Sometimes we want to press enter in the input element to submit a form, but sometimes we do not want. For example, you want to directly press the Enter key to submit the form immediately after entering the keywords. In some complex forms, you may need to avoid incorrect input keys that trigger the form submission when the form is not completed.

To control these behaviors, you do not need to use JS. the browser has already done these operations for us. Here we will summarize several rules:

  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 the button does not use input, but a button, and no type is added, the default value is type = button in IE, and the default value is type = submit in FX.
  4. Other form elements such as textarea and select do not affect the trigger rules. radio checkbox does not affect the trigger rules. 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. It should be appropriate to add a background image with CSS.

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.

This senior person remainsDemo(Click to view) to list some examples.

Reprinted: http://shake863.javaeye.com/blog/363809

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.