Solve the input input box and press the Enter key to refresh the page

When the Enter key is pressed in the input box keyboard event, the entire page is refreshed, and the user experience is quite bad. It turns out that the page will be refreshed when the form is submitted. The solution is as follows:

method one: 

<form onsubmit="return false;">....</from>

Method 2: Globally control the keyboard press event, when the key code value is 13, return false directly

document.onkeyup=function(e){
        var e = e || event;
        var currKey = e.keyCode || e.which || e.charCode;
        if (currKey == 13) {
            return false;
        }
    }

Method three 

<input type="text"  onkeyup="return ClearSubmit(event)" />

 

 function ClearSubmit(e) {
            if (e.keyCode == 13) {
                return false;
            }
   }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324974937&siteId=291194637