JS Press ENTER to implement the method of login

Source: Internet
Author: User

Press ENTER to implement the method of login can be implemented by JS, there are the following three ways:

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "> (This code is presented in Chinese for the browser)

Method One:

< html > < 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: <script> function KeyDown() {    if (event.keyCode == 13)    {      event.returnValue= false ;      event.cancel = true ;      Form1.btnsubmit.click();    } } </script>How to use: < 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: < 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 >Here Note:In the <body> we added the onkeydown attribute, so that we enter the content after the key can be directly executed JS method On_return (). Because Window.event.keyCode, if it's 13, means enter,  So we determine if we press the key is not the return, if it is we go to find the ' sub ' attribute, if found to execute the click method is. (The above three kinds of dry methods can be implemented to enter the login,)

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.