JS press the enter key to implement the login method
- 2020-03-30 03:46:26
- OfStack
In this paper, the example of JS press the enter key to achieve login method, this function has a very wide range of practical value. Share with you for your reference. Specific methods are as follows:
Method one:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Check Score</title>
<script language="JavaScript">
function keyLogin(){
if (event.keyCode==13) //The key value of the enter key is 13
document.getElementByIdx_x("input1").click(); //The login event that invokes the login button
}
</script>
</head>
<body onkeydown="keyLogin();">
<input id="input1" value=" The login " type="button" onClick="alert(' Successful call! ')">
</body>
</html>
Method 2:
<script>
function KeyDown()
{
if (event.keyCode == 13)
{
event.returnValue=false;
event.cancel = true;
Form1.btnsubmit.click();
}
}
</script>
Usage:
<form name="Form1" method="">
The user name :<INPUT TYPE=text SIZE=20 maxlength = 8 onkeydown=KeyDown()>
password :<INPUT TYPE=password SIZE=20 maxlength = 8 onkeydown=KeyDown()>
<input type="submit" name="btnsubmit" value=" submit " />
</form>
Method 3:
Every website page has a login screen, and many times after entering the user name and password, you have to click a button or link similar to login with the mouse, so that you can get into the website and do what you like.
Sometimes I wonder if I can just type in what I need to type in and hit enter to perform the login function. The solution is as follows:
Ss.html page code:
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="css/text.css" type="text/css">
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onkeydown="on_return();">
<form name ="loginForm" method="post" action="fuck.html">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="69%" height="30"><span class="font_04"> Account name </span>
<input type="text" name="userName" size="18.5">
</td>
</tr>
<tr>
<td width="69%" height="30"><span class="font_04"> password </span>
<input type="password" name="pwd" >
</td>
</tr>
<tr>
<td width="31%" height="30">
<a id="sub" onClick='check()' >
landing </a></td>
</tr>
</table>
</form>
</body>
</html>
<script language="javascript">
function check() {
var formname=document.loginForm;
if (formname.userName.value == "") {
alert(" Please enter user name! ");
formname.userName.focus();
return false;
}
if (formname.pwd.value == "") {
alert(" Please enter your password! ");
formname.pwd.focus();
return false;
}
formname.submit();
}
//When you press enter, the default is to log in
function on_return(){
if(window.event.keyCode == 13){
if (document.all('sub')!=null){
document.all('sub').click();
}
}
}
</script>
here Note: In < Body> We've added the onkeydown property so that we can directly execute the JS method on_return() after we've typed in the content.