JS method to log in by pressing the Enter key_javascript skills
The example in this article describes the JS method of pressing the Enter key to log in. This function has a very wide range of practical value. Share it with everyone for your reference. The specific method is as follows:
Method 1:
<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 2:
<script> function KeyDown() { if (event.keyCode == 13) { event.returnValue=false; event.cancel = true; Form1.btnsubmit.click(); } } </script>
Usage:
<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 3:
Any website page has a login interface. Many times after entering the username and password, you have to use the mouse to click on a button or link similar to login. Only in this way can you enter the website and do what you like to do.
Sometimes I wonder if I can just type in what I need to enter and just hit Enter to execute 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">帐户名</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>
HereNote: In
we added the onkeydown attribute, so that after we enter the content, we can directly execute the JS method on_return() by pressing the key. Because window.event.keyCode if If it is 13, it means the Enter key, so we judge whether the key we press is the Enter key. If it is, we will look for the 'sub' attribute. If we find the click method, that's it.I hope the method described in this article will be helpful to everyone’s web programming design.

JavaandJavaScriptaredistinctlanguages:Javaisusedforenterpriseandmobileapps,whileJavaScriptisforinteractivewebpages.1)Javaiscompiled,staticallytyped,andrunsonJVM.2)JavaScriptisinterpreted,dynamicallytyped,andrunsinbrowsersorNode.js.3)JavausesOOPwithcl

JavaScript core data types are consistent in browsers and Node.js, but are handled differently from the extra types. 1) The global object is window in the browser and global in Node.js. 2) Node.js' unique Buffer object, used to process binary data. 3) There are also differences in performance and time processing, and the code needs to be adjusted according to the environment.

JavaScriptusestwotypesofcomments:single-line(//)andmulti-line(//).1)Use//forquicknotesorsingle-lineexplanations.2)Use//forlongerexplanationsorcommentingoutblocksofcode.Commentsshouldexplainthe'why',notthe'what',andbeplacedabovetherelevantcodeforclari

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
