简单登陆页面制作(HTML+CSS+JS)

本章为新手制作简单登陆页面分享。

登陆html代码如下:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>管理系统</title>
    <link rel="stylesheet" type="text/css" href="style.css"> <!--引入样式-->
    <script type="text/javascript" src="login.js"></script>  <!--引入脚本-->
</head>
<body>
    <div>
        <form name="f" onsubmit="check(this)">  <!--表单区,placeholder属性规定填充内容-->
            <h1>网站登陆系统</h1>
            <input type="text" id="name" placeholder="用户"><br>
            <input type="password" id="pass" placeholder="密码"><br>
            <input type="button" onclick="check(this)" value="登录">
            <p>© 2024 ocean 版权所有</p>
        </form>
    </div>
</body>
</html>

登陆成功html页面如下:

<!DOCTYPE html>
<html>
<head>
    <title>系统首页</title>
    <meta charset="utf-8">
</head>
<body>
    <h1>登录成功!欢迎回来。</h1>
</body>
</html>

css代码如下:

html{
    background-image: url("fj.jpg");
}
 
form{
    text-align: center;
    position: absolute;   /*表单于页面居中*/
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}
 
input[type=text],input[type=password]{
    background-color: white;  /*正常状态样式*/
    color: black;
    border: 0;
    border-radius: 20px;
    outline: 0;
    text-align: center;
    height: 50px;
    width: 250px;
    margin: 5px;
}
 
input[type=button]{
    background-color: #45A0F2;  /*正常状态样式*/
    color: white;
    border: 0;
    border-radius: 20px;
    outline: none;
    text-align: center;
    height: 50px;
    width: 250px;
    margin: 5px;
}
 
input[type=text]:hover,input[type=password]:hover{
    outline: 0;  /*悬停时样式*/
    background-color: #65BCD6;
    color: white;
    box-shadow: 0 8px 16px 0 rgba(0,0,0,0.45), 0 6px 20px 0 rgba(0,0,0,0.19);  /*阴影*/
}
 
input[type=button]:hover{
    outline: 0;  /*悬停时样式*/
    background-color:#168DBE;
    color: white;
    box-shadow: 0 8px 16px 0 rgba(0,0,0,0.45), 0 6px 20px 0 rgba(0,0,0,0.19);  /*阴影*/
}

js代码如下:

function check(thisform) {
 
    var name=document.getElementById("name").value;  //读取表单数据,创建变量
    var pass=document.getElementById("pass").value;
 
    if (name=="admin" && pass=="123456" || name=="admin2" && pass=="456789") {  
        //验证变量。此处设置账号、密码(可设置多组,用||隔开)
        alert("登录成功!");
        window.document.f.action="index.html";  //此处设置登录后跳转页面
        window.document.f.submit();
    }
    else{
        alert("用户名或密码错误!");
    }
 
}

背景图

登陆失败结果图:

登陆成功结果图

感谢观看。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值