js cursor positioning text box carriage return Form submission problem solution

  • 2020-06-12 08:29:01
  • OfStack

This article describes the js cursor positioning text box carriage return form submission solution. Share to everybody for everybody reference. The specific analysis is as follows:

The json string returned by the method appears on the page when the cursor is positioned after the text box for the auxiliary lookup is entered.

The reason: When there only one text input field a form, the user agent accept in field as a request to the form accept in field as a request to the form

When there is only 1 input type="text" in form, this form will be submitted when the user presses enter.

Solution: Handle the onkeydown event of input text, and forbid the carriage return operation.

Specific code:

<input class="text text-1" type="text" name="name" 
id="notAssociateName" value="" onkeydown="enter_down(event);"/>
function enter_down(event){
function stopDefault(e) {
 // If an event object is provided, this is 1 A non IE The browser 
 if(e && e.preventDefault) {
   // Block default browser actions 
 } else {
   //IE Block the default action of the function 
   window.event.returnValue = false;
 return false;

I hope this article has been helpful for your javascript programming.

Related articles: