JS Press ENTER to implement the method of login

Source: Internet
Author: User

The example of this paper describes the JS press ENTER to implement the login method, the function has a very wide range of practical value. Share it for everyone's reference. Here's how:

Method One:

?
1234567891011121314 <html xmlns="http://www.w3.org/1999/xhtml" ><head><title>Check Score</title><script language="JavaScript">function keyLogin(){ if (event.keyCode==13)  //回车键的键值为13   document.getElementByIdx_x("input1").click(); //调用登录按钮的登录事件}</script></head><body onkeydown="keyLogin();"><input id="input1" value="登录" type="button" onClick="alert(‘调用成功!‘)"></body></html>

Method Two:

?
1234567891011 <SCRIPT> function keydown () { &NBSP;&NBSP; Code class= "JS keyword" >if     { &NBSP;&NBSP;&NBSP;&NBSP; event.returnvalue= false &NBSP;&NBSP;&NBSP;&NBSP; event.cancel = true &NBSP;&NBSP;&NBSP;&NBSP; form1.btnsubmit.click (); &NBSP;&NBSP; " } </SCRIPT>

How to use:

?
12345 <form name="Form1" method="">用户名:<INPUT TYPE=text SIZE=20 maxlength = 8 onkeydown=KeyDown()>密码:<INPUT TYPE=password SIZE=20 maxlength = 8 onkeydown=KeyDown()><input type="submit" name="btnsubmit" value="提交" /></form>

Method Three:

Any site page has a login interface, many times after the user name and password, but also to use the mouse to point a similar to the landing button or link. So you can go to the website and do what you like.
Sometimes I wonder if I can enter the things I want to enter, and then directly hit enter to perform the landing function? The workaround is as follows:

Ss.html page Code:

?
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 <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">帐户名</span>  <input type="text" name="userName" size="18.5"> </td>    </tr>    <tr> <td width="69%" height="30"><span class="font_04">密 码</span>  <input type="password" name="pwd" > </td>    </tr>    <tr> <td width="31%" height="30"> <a id="sub" onClick=‘check()‘ > 登陆</a></td>    </tr>   </table>  </form></body></html><script language="javascript">function check() {    var formname=document.loginForm;   if (formname.userName.value == "") {    alert("请输入用户名!");    formname.userName.focus();    return false;  }  if (formname.pwd.value == "") {    alert("请输入密码!");    formname.pwd.focus();    return false;  }  formname.submit();}  //回车时,默认是登陆 function on_return(){ if(window.event.keyCode == 13){  if (document.all(‘sub‘)!=null){   document.all(‘sub‘).click();   } } }</script>

Note here: in the <body> we added the onkeydown attribute, so that we input good content after the key can be directly executed JS method On_return (). Because Window.event.keyCode, if it's 13, , which means enter, so we determine if we press the key is not the return, if we are to find the ' sub ' property, if the execution click Method is found.

It is hoped that the method described in this article will be helpful to everyone's web design.

JS Press ENTER to implement the method of login

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.