js 验证用户身份,登录成功之后等待一定秒数,跳转到操作页面。使用 window 函数。代码如下
Javascript 是一种由 Netscape 的 LiveScript 发展而来的原型化继承的基于对象的动态类型的区分大小写的客户端脚本语言,主要目的是为了解决服务器端语言,比如 Perl,遗留的速度问题,为客户提供更流畅的浏览效果。
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <title>
- Login.html
- </title>
- <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
- <meta http-equiv="description" content="this is my page">
- <meta http-equiv="content-type" content="text/html; charset=UTF-8">
- <!--<link rel="stylesheet" type="text/CSS" href="./styles.css">-->
- <script type="text/javascript">
- function checkuser() {
- if ($('uname' == "lala") && $('pwd') == "123") {
- return true;
- } else {
- return false;
- }
- }
- function $(id) {
- return document.getElementById(id).value;
- }
- </script>
- </head>
- <body>
- <form action="ok.html">
- u:
- <input type="text" id="uname" />
- <br>
- p:
- <input type="password" id="pwd" />
- <br>
- <input type="submit" value="登录" onclick="return checkuser()" />
- </form>
- </body>
- </html>
这是登录页面,只有当用户名为 lala,密码为 123 时登录成功。在 onclick 事件处使用 return, 是在用户名和密码输入不符时,阻止页面跳转。登录成功页面中,含有等待秒数,代码为:
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <title>
- ok.html
- </title>
- <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
- <meta http-equiv="description" content="this is my page">
- <meta http-equiv="content-type" content="text/html; charset=UTF-8">
- <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
- <script type="text/javascript">
- function tiao() { clearInterval(mytime); window.open("manage.html", "_self");
- } setTimeout("tiao()", 5000);
- function changeSec() { //得到myspan值
- $('myspan').innerText = $('myspan').innerText - 1;
- }
- function $(id) {
- return document.getElementById(id);
- }
- var mytime = setInterval("changeSec()", 1000);
- </script>
- </head>
- <body>
- 登录成功,
- <span id="myspan">
- 5
- </span>
- 秒后自动跳转到管理页面
- </body>
- </html>
关键在几个函数的使用,setTimeout("tiao()",5000); 函数是打开页面,等待 5 秒,调用 tiao() 函数。setInterval("changeSec()",1000); 函数是每隔 1 秒调用一次 changeSec() 函数。这样就完成了简单的登录功能。
来源: