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