溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

JS、CSS和HTML怎么實(shí)現(xiàn)注冊(cè)頁(yè)面

發(fā)布時(shí)間:2021-07-05 09:15:26 來源:億速云 閱讀:182 作者:小新 欄目:開發(fā)技術(shù)

小編給大家分享一下JS、CSS和HTML怎么實(shí)現(xiàn)注冊(cè)頁(yè)面,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

更新:使用JavaScript實(shí)現(xiàn)用戶名和密碼表單校驗(yàn)功能。

代碼如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注冊(cè)頁(yè)面</title>
    <style>
        *{
            margin: 0px;
            padding: 0px;
            box-sizing: border-box;
        }
        body{
            background: url("img/register_bg.png") no-repeat center;
            padding-top: 25px;
        }

        .rg_layout{
            width: 900px;
            height: 500px;
            border: 8px solid #EEEEEE;
            background-color: white;
            /*讓div水平居中*/
            margin: auto;
        }

        .rg_left{
            /*border: 1px solid red;*/
            float: left;
            margin: 15px;
        }
        .rg_left > p:first-child{
            color:#FFD026;
            font-size: 20px;
        }

        .rg_left > p:last-child{
            color:#A6A6A6;
            font-size: 20px;

        }
        .rg_center{
            float: left;
            /* border: 1px solid red;*/

        }

        .rg_right{
            /*border: 1px solid red;*/
            float: right;
            margin: 15px;
        }

        .rg_right > p:first-child{
            font-size: 15px;

        }
        .rg_right p a {
            color:pink;
        }

        .td_left{
            width: 100px;
            text-align: right;
            height: 45px;
        }
        .td_right{
            padding-left: 50px ;
        }

        #username,#password,#email,#name,#tel,#birthday,#checkcode{
            width: 251px;
            height: 32px;
            border: 1px solid #A6A6A6 ;
            /*設(shè)置邊框圓角*/
            border-radius: 5px;
            padding-left: 10px;
        }
        #checkcode{
            width: 110px;
        }

        #img_check{
            height: 32px;
            vertical-align: middle;
        }

        #btn_sub{
            width: 150px;
            height: 40px;
            background-color: #FFD026;
            border: 1px solid #FFD026 ;
        }
        .error {
            color: red;
        }
        #td_sub {
            padding-left: 150px;
        }

    </style>

    <script>
        //實(shí)現(xiàn)賬戶密碼表單校驗(yàn)
        window.onload = function () {
            //給表單綁定onsubmit事件
            //也就是點(diǎn)擊注冊(cè)按鈕就會(huì)驗(yàn)證用戶名和密碼是否正確
            document.getElementById("form").onsubmit = function () {
                //調(diào)用用戶校驗(yàn)方法  checkUsername();
                //調(diào)用密碼校驗(yàn)方法  checkPassword();
                return checkUsername() && checkPassword();
            }

            //給用戶名和密碼分別綁定離焦事件
            //當(dāng)離焦時(shí)就會(huì)校驗(yàn)用戶名和密碼是否正確
            //注意這里的方法沒有括號(hào)
            document.getElementById("username").onblur = checkUsername;
            document.getElementById("password").onblur = checkPassword;
        }

        //校驗(yàn)用戶名
        function checkUsername() {
            //1、獲取用戶名的值
            var username = document.getElementById("username").value;
            //2、定義正則表達(dá)式
            var reg_username = /^\w{6,12}$/;
            //3、判斷值是否符合正則的規(guī)則
            var flag = reg_username.test(username);
            //4、提示信息
            var s_username = document.getElementById("s_username");

            if (flag) {
                //提示綠色對(duì)勾
                s_username.innerHTML = "<img width='35' height='25' src='img/gou.png' />";
            } else {
                //提示紅色用戶名有誤
                s_username.innerHTML = "用戶名格式有誤";
            }
            return flag;
        }

        //校驗(yàn)密碼
        function checkPassword() {
            //1、獲取用戶名的值
            var password = document.getElementById("password").value;
            //2、定義正則表達(dá)式
            var reg_password = /^\w{6,12}$/;
            //3、判斷值是否符合正則的規(guī)則
            var flag = reg_password.test(password);
            //4、提示信息
            var s_password = document.getElementById("s_password");

            if (flag) {
                //提示綠色對(duì)勾
                s_password.innerHTML = "<img width='35' height='25' src='img/gou.png' />";
            } else {
                //提示紅色用戶名有誤
                s_password.innerHTML = "密碼格式有誤";
            }
            return flag;
        }


    </script>
</head>
<body>

<div class="rg_layout">
    <div class="rg_left">
        <p>新用戶注冊(cè)</p>
        <p>USER REGISTER</p>

    </div>

    <div class="rg_center">
        <div class="rg_form">
            <!--定義表單 form-->
            <form action="#" id="form" method="get">
                <table>
                    <tr>
                        <td class="td_left"><label for="username">用戶名</label></td>
                        <td class="td_right">
                            <input type="text" name="username" id="username" placeholder="請(qǐng)輸入用戶名">
                            <span id="s_username" class="error"></span>
                        </td>
                    </tr>

                    <tr>
                        <td class="td_left"><label for="password">密碼</label></td>
                        <td class="td_right">
                            <input type="password" name="password" id="password" placeholder="請(qǐng)輸入密碼">
                            <span id="s_password" class="error"></span>
                        </td>
                    </tr>

                    <tr>
                        <td class="td_left"><label for="email">Email</label></td>
                        <td class="td_right"><input type="email" name="email" id="email" placeholder="請(qǐng)輸入郵箱"></td>
                    </tr>

                    <tr>
                        <td class="td_left"><label for="name">姓名</label></td>
                        <td class="td_right"><input type="text" name="name" id="name" placeholder="請(qǐng)輸入姓名"></td>
                    </tr>

                    <tr>
                        <td class="td_left"><label for="tel">手機(jī)號(hào)</label></td>
                        <td class="td_right"><input type="text" name="tel" id="tel" placeholder="請(qǐng)輸入手機(jī)號(hào)"></td>
                    </tr>

                    <tr>
                        <td class="td_left"><label>性別</label></td>
                        <td class="td_right">
                            <input type="radio" name="gender" value="male"> 男
                            <input type="radio" name="gender" value="female"> 女
                        </td>
                    </tr>

                    <tr>
                        <td class="td_left"><label for="birthday">出生日期</label></td>
                        <td class="td_right"><input type="date" name="birthday" id="birthday" placeholder="請(qǐng)輸入出生日期"></td>
                    </tr>

                    <tr>
                        <td class="td_left"><label for="checkcode" >驗(yàn)證碼</label></td>
                        <td class="td_right"><input type="text" name="checkcode" id="checkcode" placeholder="請(qǐng)輸入驗(yàn)證碼">
                            <img id="img_check" src="img/verify_code.jpg">
                        </td>
                    </tr>

                    <tr>
                        <td colspan="2" id="td_sub"><input type="submit" id="btn_sub" value="注冊(cè)"></td>
                    </tr>
                </table>

            </form>

        </div>

    </div>

    <div class="rg_right">
        <p>已有賬號(hào)?<a href="#"  >立即登錄</a></p>
    </div>

</div>
</body>
</html>

運(yùn)行效果:

JS、CSS和HTML怎么實(shí)現(xiàn)注冊(cè)頁(yè)面

JS、CSS和HTML怎么實(shí)現(xiàn)注冊(cè)頁(yè)面

以上是“JS、CSS和HTML怎么實(shí)現(xiàn)注冊(cè)頁(yè)面”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI