Home  >  Article  >  Web Front-end  >  网页前端登录js按Enter回车键实现登陆的两种方法_javascript技巧

网页前端登录js按Enter回车键实现登陆的两种方法_javascript技巧

WBOY
WBOYOriginal
2016-05-19 10:42:451391browse

很简单的代码,这里介绍两种方法给大家、

第一种:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" > 
<head> 
<title>Check Score</title> 
<mce:script language="JavaScript"><!-- 
  function keyLogin(){ 
    if (event.keyCode==13)  //回车键的键值为13 
       document.getElementById("input1").click(); //调用登录按钮的登录事件 
    } 
// --></mce:script> 
</head> 
 
<body onkeydown="keyLogin();"> 
    <input type="text" /> 
    <input type="text" /> 
    <input type="text" /><input type="text" /> 
    <input type="text" /><input type="text" /> 
    <!--<input id="input1" value="登录" type="button" onclick="alert('调用成功!')">--> 
    <img  id="input1" onclick="alert('调用成功!')"/ alt="网页前端登录js按Enter回车键实现登陆的两种方法_javascript技巧" > 
</body> 
 
</html>

第二种:

<script>
function KeyDown()
{
  if (event.keyCode == 13)
  {
    event.returnValue=false;
    event.cancel = true;
    Form1.btnsubmit.click();
  }
}
</script>

使用方法:
<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>

以上这篇网页前端登录js按Enter回车键实现登陆的两种方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn