Javascript登录页面“记住密码”实现

柔光的暖阳◎ 2021-09-30 10:20 470阅读 0赞

  JS记住密码实现效果:

JavaScript Code











1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32
 

<!DOCTYPE html>

<html>

    <head>

        <title>用户名密码</title>

        <script type=
“text/javascript”
 src=
“http://ajax.microsoft.com/ajax/jquery/jquery-1.4.min.js“
></script>
        <script>
            

function
 SavePassword()
            {
                

if
(document.getElementById(
“savePassword”
).checked)
                {
                    

var
 username = $(
“#username”
).val();
                    

var
 password = $(
“#password”
).val();
                    window.sessionStorage.username =  username;
                    window.sessionStorage.password = password;
                    localStorage.rmbPassword = 

true
;
                }
                

else

                {
                    localStorage.rmbPassword = 

false
;
                }
            }
        </script>
    </head>
    <body>
        <label id=

“login”
 
for
=
“username”
 style=
“margin:auto;font-size:15px”
>用户名:</label>
        <input style=

“margin:auto;font-size:15px”
 type=
“text”
 name=
“username”
 id=
“username”
  placeholder=
“输入用户名…”
 >
        <br><br>
        <label id=

“login”
 
for
=
“password”
 style=
“margin:auto;font-size:15px”
>密&nbsp&nbsp&nbsp码:</label>
        <input style=

“margin:auto;font-size:15px”
 type=
“password”
 name=
“password”
 id=
“password”
 placeholder=
“输入密码…”
>
        <input type=

“checkbox”
 name=
“savePassword”
 id=
“savePassword”
 checked=
“checked”
 οnclick=
“SavePassword()”
>
    </body>
</html>

1012444-20171107123954606-285543455.png

转载于:https://www.cnblogs.com/MakeView660/p/7798489.html

发表评论

表情:
评论列表 (有 0 条评论,470人围观)

还没有评论,来说两句吧...

相关阅读

    相关 js如何实现登录记住密码

    常见的很多网站登录,都有记住密码功能,下面是用js实现的记住密码功能(代码用的源生js,不用引入任何插件,大家如果引入了jQuery,可以进行修改,优化) js部分