JS implements the keyboard Enter key to submit the form

Please indicate the source of the original reprint: http://agilestyle.iteye.com/blog/2381878

 

Write JS scripts

function enterDown(e){
	var keycode = 0;

	if(isFirefox()) {
		keycode = e.which;
	} else {
		keycode = e.keyCode;
	}

	if (keycode === 13 ) { //Enter key is 13
		if(googleFlag) {
			loginWithGoogle(); // requires google to verify login
		} else {
			loginWithoutGoogle(); // does not require google to verify login
		}
	}
}

function isFirefox(){
	if (navigator.userAgent.indexOf("Firefox") > -1) {
		return true;
	} else {
		return false;
	}
}

 

Just import the script you wrote in the body tag

<body onkeydown="enterDown(event);">

Note:

Tested under Chrome, Firefox, and IE

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326678121&siteId=291194637