js实现漂亮的注册页面(js动态注册页面)

代码:

javascript 复制代码
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册</title>
    <style>
        body{
            background-color: #ece9f0;
        }
        .box{
            width: 800px;
            height: 300px;
            margin: 0 auto;
            margin-top: 20px;
            box-shadow: 0px 0px 20px black;
            background-color: #c8e0c8;
            padding-top: 30px;
            text-align: center;
            font-size: 18px;
        }
  
       label{
            display: inline-block;
            width: 80px;
       }
       .msg{
            margin-top: 20px;
       }
       input{
            height: 20px;
            border: 0;
       }
       input::placeholder{
            color: #f7c7d9;
       }
       .zc{
            font-size: 30px;
            font-weight: bold;
       }
       .djzc{
            color: skyblue;
            border: 0;
            font-weight: bold;
            width: 80px;
            height: 30px;
       }
    </style> 
</head>
<body>
    <div class="box">
       <div class="zc">注册页</div>
       <div class="msg">
            <label class="yhm">用户名:</label><input type="text" placeholder="请输入用户名">
       </div>
       
       <div class="msg">
            <label class="pwd">密码:</label><input type="password" placeholder="请输入密码">
       </div>
       <div class="msg">
            <label class="name">姓名:</label><input type="text" placeholder="请输入姓名">
       </div>
       <div class="msg">
            <button class="djzc" onclick="registerfun()">点击注册</button>
       </div>
       
    </div>
    <script src="https://api.vvhan.com/api/script/snow"></script>
    <script src="https://api.vvhan.com/api/script/bolang"></script>
    <script src="https://api.vvhan.com/api/script/yinghua"></script>
    <script src="https://api.vvhan.com/api/script/yinghua"></script>
    <script src="https://api.vvhan.com/api/script/denglong"></script>
    <script>
        let box = document.querySelector('.box')
        let zc = document.querySelector('.zc')
        let yhm = document.querySelector('.yhm')
        let pwd = document.querySelector('.pwd')
        let name = document.querySelector('.name')


        setInterval(()=>{
            box.style.boxShadow=`0px 0px 20px rgb(${sj()},${sj()},${sj()})`
            zc.style.color=`rgb(${sj()},${sj()},${sj()})`
            yhm.style.color=`rgb(${sj()},${sj()},${sj()})`
            pwd.style.color=`rgb(${sj()},${sj()},${sj()})`
            name.style.color=`rgb(${sj()},${sj()},${sj()})`
            zc.style.textShadow=` 0px 0px 10px rgb(${sj()},${sj()},${sj()})`
        },1000)
        function sj(){
            return Math.floor(Math.random()*255)
        }
         // 点击之后的注册方法
         function registerfun(params) {
             // 获取输入框的内容
            let user_name = document.querySelectorAll('input')[0].value
            let password = document.querySelectorAll('input')[1].value
            let real_name = document.querySelectorAll('input')[2].value
            // 准备ajax向后端发送数据
            let xhr = new XMLHttpRequest()
            // 请求方式和请求地址
            xhr.open('post','http://api.poiuy.top/users/register')
            xhr.setRequestHeader('Content-type','application/json')
            xhr.send(JSON.stringify({
                user_name,
                password,
                real_name
            }))
            xhr.onload= function(params) {
                let data = JSON.parse(xhr.responseText);
                    console.log(data.code);
                    // 判断状态码
                    // 如果是0代表成功 跳转到登陆
                if (data.code==0) {
                    alert('注册成功,即将跳转登录页')
                    window.open('login.html')
                }else{
                    // 否则提示错误信息
                    alert(data.message)
                    
                }  
            }  
        }
        
       
  
    </script>
</body>
</html>

效果图:

相关推荐
Java展博2 小时前
[前端够用就好] 跨域报错时,浏览器到底在拦谁
前端·状态模式
用户112936112192 小时前
npm 都提示成功了,node_modules 为什么还占着 370M?
linux·前端·后端
掘金安东尼4 小时前
Agent Harness 也有 benchmark:评分榜与评测工作台现状
前端·agent
digger_4194 小时前
从零理解 Electron:主进程、渲染进程、preload 与 IPC 实战
前端·electron
去伪存真5 小时前
别让你的 RAG 平台“花五份钱、答一份结巴的题”:幂等性架构的自我修养
前端·agent
snow@li5 小时前
前端:导入EXCEL并解析文件内容,demo
前端·javascript·vue.js
补码缩写6 小时前
压缩PNG不损失透明:只量化RGB、alpha原样留的减色流程
前端
TDengine (老段)6 小时前
TDengine IDMP 知识库与知识图谱
大数据·前端·物联网·知识图谱·时序数据库·tdengine·涛思数据
goehou8 小时前
PNG 转 WebP 不一定变小,我量了三类图
前端·性能优化·webp·sharp
夕水8 小时前
一个小小的颜色选择器,差点让我开发出一个组件库来
前端·javascript·typescript