HTML访问需密码,输入密码正确后跳转到另一页面

效果展示

完整代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
<style>
    html {
  height:100%;
  background-image:url(../../INFORMATION/IMAGE/BJ.jfif);
  background-size:cover;  /* 让背景图基于容器大小伸缩 */
}
        #son {
        position: absolute;
        left: 50%;
        top: 80%;
        transform: translateX(-50%) translateY(-50%);
}
.box{
  width: 400px;
  height: 40px;
  display: inline-block;
  text-align: center;
  padding-top: 5px;
  transition:0.5s;
  background-color: transparent; 
  font-size: 2rem;
}
.box:hover
{
transform: scale(1.5);
}
    
</style>
</head>
<body style="background-color:black">
    
    <div id="son"><input id="password" class="box" onclick="huiche()"><br>
    </div>
 
 
    <script>
    function huiche(){
        document.onkeydown = function(e){
            if((e||event).keyCode==13&&document.getElementById("password").value=="zjrzdgdfFGZHDS")
            window.location.href='G.html';
        };
    }
    </script>
</body>
</html>

关键语句:
<div id="son"><input id="password" class="box" οnclick="huiche()"><br></div>

解释:
id="password"用于记录输入的内容

οnclick="huiche()"点击后调用huiche()函数

鼠标放上去后transform: scale(1.5);放大的倍数。transition:0.5s;放大的时间。

background-color: transparent;透明

关键语句:
function huiche(){

        document.onkeydown = function(e){

 if((e||event).keyCode==13&&document.getElementById("password").value=="zjrzdgdfFGZHDS")

            window.location.href='G.html';

        };

    }

解释:
document.onkeydown = function(e)检测键盘,传递数值

 if((e||event).keyCode==13 13是回车键对应的数字,“如果按下回车”

document.getElementById("password").value获得输入的值

=="zjrzdgdfFGZHDS"判断是否等于设置的密码

window.location.href='G.html';填写要打开网页的地址,正确就跳转,不对就循环。

  • 8
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值