Js implementation of simple login function instance code

  • 2020-03-27 00:11:18
  • OfStack


<!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=" The login " onclick="return checkuser()"/>
    </form>
  </body>
</html>


This is the login page, only if the user name is lala and the password is 123. Using return on the onclick event prevents the page from jumping if the username and password don't match. The login success page contains the number of waiting seconds. The code is:


<!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() {
           //Get myspan value
           $('myspan').innerText=$('myspan').innerText-1;
        }

         function $(id) {
        return document.getElementById(id);
      }
        var mytime = setInterval("changeSec()",1000);
    </script>
  </head>

  <body>
     Login successful, <span id="myspan">5</span> After the second automatically jumps to the management page 
  </body>
</html>


Key in the use of several functions, setTimeout("tiao()",5000); The function opens the page, waits 5 seconds, and calls the tiao() function. SetInterval (changeSec "()", 1000); The changeSec() function is called every 1 second. This completes the simple login function.


Related articles: