The solution to the problem of submitting the return form of JS cursor positioning text box

Source: Internet
Author: User

This article illustrates the solution to the problem of submitting the return form of JS cursor positioning text box. Share to everyone for your reference. The specific analysis is as follows:

When the cursor is positioned at the back of the text box in the secondary lookup, the page appears with the JSON string returned by the method.

Reason: When there are only one single-line text input field in a form, the user agent should accept Enter into that field as a re Quest to submit the form.

When there is only one input type= "text" in the form, when the user presses ENTER, the form is submitted.

Solution: The input text onkeydown event to do processing, prohibit carriage return operation.

Specific code:

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19-20 <p> <input class= "text text-1" type= "text" name= "name" id= "Notassociatename" value= "" onkeydown= "Enter_down ( event); " /> </p> function Enter_down (event) {if (event.keycode==13) {Stopdefault (event)}} function Stopdefault (e) {//AS   If the event object is provided, then this is a non IE browser if (e && e.preventdefault) {//block default browser action E.preventdefault ();} else {//ie prevents the default action of the function in the way Window.event.returnValue = false; return false; }

I hope this article will help you with your JavaScript programming.

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.