老师,求那个换密码颜色的js代码怎么写的啊,没有头绪

老师,求那个换密码颜色的js代码怎么写的啊,没有头绪

# 具体遇到的问题

# 报错信息的截图

# 相关课程内容截图

# 尝试过的解决思路和结果

# 粘贴全部相关代码,切记添加代码注释(请勿截图)

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Document</title>

    <link rel="stylesheet" href="./css/test.css">

</head>

<body>

<header class="header">

    <div class="header__wrap">

        <div class="header__logo">慕课高铁客户服务中心&nbsp;<strong>|</strong>&nbsp;

            <span class="header__logo__client">客户服务</span>

        </div>

    <nav class="header__nav">

        <ul class="header__nav-list">

            <li class="header__nav-list__item">

                <span>意见反馈&nbsp;</span>

                <a href="#" class="header__nav-list__item_orange">imooc@.com</a>

            </li>

            <li class="header__nav-list__item">

                <span>您好,请&nbsp;</span>

                <a href="#" class="header__nav-list__item_orange">登录</a>&nbsp;|&nbsp;<a href="#">注册</a>

            </li>

            <li class="header__nav-list__item header__nav-list__imooc">

                <span>我的IMOOC</span>

                <div class="header__nav-list__imooc__triangle"></div>

                <div class="header__nav-list__imooc__menu">

                    <ul class="header__nav-list__imooc__menu__list">

                        <li class="header__nav-list__imooc__menu__list__item">

                            <a href="#">未完成订单</a><br/>

                            <a href="#">已完成订单(改/退)</a>

                        </li>

                        <li class="header__nav-list__imooc__menu__list__item">

                            <a href="#">我的保险</a>

                        </li>

                        <li class="header__nav-list__imooc__menu__list__item">

                            <a href="#">查看个人信息</a><br/>

                            <a href="#">账户安全</a>

                        </li>

                        <li class="header__nav-list__imooc__menu__list__item">

                            <a href="#">常用联系人</a>

                        </li>

                        <li class="header__nav-list__imooc__menu__list__item">

                            <a href="#">重点旅客预约</a><br/>

                            <a href="#">遗失物品查找</a>

                        </li>

                        <li class="header__nav-list__imooc__menu__list__item">

                            <a href="#">服务查询</a>

                        </li>

                        <li class="header__nav-list__imooc__menu__list__item">

                            <a href="#">投诉</a><br/>

                            <a href="#">建议</a>

                        </li>

                    </ul>

                </div>

            </li>

            <li class="header__nav-list__item">

                <img src="./img/未标题-1.png" class="header__nav-list__phone__pic">

                <span><a href="#">手机版</a></span>

            </li>

        </ul

    </nav>

    </div><!-- header__wrap -->

</header>

<!-- 主页区 -->

<div class="content">

    <h3>您现在所在的位置:<span>客运首页</span>&nbsp;>&nbsp;<span>注册</span></h3>

    <div class="main">

        <div class="main_title">账户信息</div>

        <div class="main_item">

            <span class="main_item-important">*</span>

            <label for="" class="main_item-userAccount"><span>用户名</span>:</label>

            <input type="text" id="userAccount" placeholder=" 用户设置成功后不可修改">

            <span class="main_item_"></span>

        </div

     


        <div class="main_item">

            <span class="main_item-important">*</span>

            <label for="" class="main_item-userPass"><span>登录密码</span>:</label>

            <input type="password" id="userPass" placeholder=" 6-20位字母,数字或符号">

            <span class="main_item_">

                <span class="red">1</span>

                <span class="orange">2</span>

                <span class="green">3</span>

            </span>

        </div>


        <div class="main_item">

            <span class="main_item-important">*</span>

            <label for="" class="main_item-userPass_"><span>确认密码</span>:</label>

            <input type="password" id="userPass_" placeholder=" 再次输入您的登录密码">

            <span class="main_item_"></span>

        </div>

        <!-- <p class="main_item_"></p> -->


        <div class="main_item">

            <span class="main_item-important">*</span>

            <label for="" class="main_item-userName"><span>姓名</span>:</label>

            <input type="text" id="userName" placeholder=" 请输入姓名">

            <div class="namerule">

                <a href="javascript:;">姓名填写规则</a>

                <div class="namerule_"><p>1.确认姓名中生僻字无法输入时,可用生僻字拼音或同音字替代。</p>

                    <p>2.输入姓名保存后,遇有系统无法正确显示的汉字,可用该汉字的拼音或同音字重新修改后保存。</p>

                    <p>3.姓名中有繁体字无法输入时,可用简体替代。</p>

                    <p>4.姓名较长,汉字与英文字符会计超过30个(1个汉字算2个字符)的,需按姓名中第一个汉字或英文字符开始按顺序连续输入30个字符(空格字符不输入),其中英文字符输入时不区别大小写</p>

                </div>

            </div>

            <span class="main_item_"></span>

        </div>


        <div class="main_item">

            <span class="main_item-important">*</span>

            <label for="" class="main_item-idType"><span>证件类型</span>:</label>

            <select id="idType">

                <option value="二代身份证">二代身份证</option>

                <option value="港澳通行证">港澳通行证</option>

            </select>

        </div>


        <div class="main_item">

            <span class="main_item-important">*</span>

            <label for="" class="main_item-information"><span>证件号码</span>:</label>

            <input type="text" id="information" placeholder=" 请输入您的证件号码">

            <span class="main_item_"></span>

        </div>

        <!-- <p class="main_item_"></p> -->


        <div class="main_item">

            <span class="main_item-important" style="color: #fff;">*</span>

            <label for="" class="main_item-email"><span>邮箱</span>:</label>

            <input type="email" id="email" placeholder=" 请正确填写邮箱地址">

            <span class="main_item_"></span>

        </div>

        <!-- <p class="main_item_"></p> -->


        <div class="main_item">

            <span class="main_item-important">*</span>

            <label for="" class="main_item-telephone"><span>手机号码</span>:</label>

            <input type="tel" id="telephone" placeholder=" 请输入您的手机号码">

            <span class="main_item_"></span>

        </div>

        <!-- <p class="main_item_"></p> -->


        <div class="main_item">

            <span class="main_item-important">*</span>

            <label for="" class="main_item-userType"><span>旅客类型</span>:</label>

            <select id="userType">

                <option value="成人">成人</option>

                <option value="未成年">未成年</option>

            </select>

        </div>

      

        <div id="main_end">

            <div id="choose"><input type="checkbox" id="choose">我已阅读并同意遵守<a href="javascript:;">《中国铁路客户服务中心网站服务条款》</a></div>

            <button id="handup">下一步</button>

        </div>

    </div>

</div>

<!-- 尾部区域 -->

<footer class="footer">

    <p>关注我们|网站声明</p>

    <P>Copyright© 2017 imooc.com All Rights Reserved | 京ICP备 13046642号-2 | 网站声明</P>

</footer>

<script type="text/javascript" src="./js/index.js"></script>

</body>

</html>


*{

    margin0;

    padding0;

    list-stylenone;

    text-decorationnone;

    box-sizingborder-box;

}

body{min-width1200px;}

a{colorinherit;}


/* 页头区 */

header{

    background-colorrgb(239239239);

    border-bottom2px solid rgb(36135201);

}

.header__nav-list__item span{cursorpointer;}

.header__wrap{

    width1250px;

    height110px;

    margin0 auto;

    positionrelative;

}

/* 头部左边logo */

.header__logo{

    width500px;

    height100px;

    line-height100px;

    text-indent100px;

    letter-spacing2px;

    font-size24px;

    positionabsolute;

    top50%;

    margin-top-50px;

    left0;

    background:url('../img/logo.png'left center no-repeat;

    background-size100px 100px;

    cursorpointer;

}

.header__logo__client{

    font-size18px;

    colorrgb(102102102);

}

/* 头部右边导航 */

.header__nav{

    height100px;

    positionabsolute;

    top50%;

    margin-top-50px;

    right0;

}

.header__nav-list{

    height100px;

    line-height100px;

}

.header__nav-list__item{

    floatleft;

    padding0 10px;

    letter-spacing:1px;

}

.header__nav-list__item_orange{

    colorrgb(2511163);

}

.header__nav-list__imooc{

    positionrelative;

}

.header__nav-list__imooc__triangle{

    width0;

    height0;

    border-left10px solid transparent;

    border-right10px solid transparent;

    border-top10px solid #000;

    positionabsolute;

    top45%;

    right-15px;

    cursorpointer;

}

/* nav导航 隐藏下拉框 */

.header__nav-list__imooc__menu{

    width163px;

    height300px;

    positionabsolute;

    left0;

    top70px;

    border1.5px solid rgb(2511163);

    background-colorrgb(247247247);

    overflowhidden;

    displaynone;

}

.header__nav-list__imooc:hover

.header__nav-list__imooc__menu{

    displayblock;

}

.header__nav-list__imooc__menu__list{

    font-size13px;

    colorrgb(119119119);

    text-aligncenter;

    padding0 10px;

    overflowhidden;

}


.header__nav-list__imooc__menu__list__item:last-child{

    border-bottomnone;

}

.header__nav-list__imooc__menu__list__item{

    width130px;

    line-height26px;

    text-alignleft;

    padding-left10px;

    border-bottom1.5px dotted rgb(119119119);

}

/* nav导航 手机版 */

.header__nav-list__phone{

    padding-left50px;

}

.header__nav-list__phone__pic{

    width20px;

    vertical-alignmiddle;

    margin-left40px;

}

/* 判断 */

.main_item_{

    positionabsolute;

    top50%;

    margin-top-10px;

    left50%;

    margin-left-40px;

}

/* 主体头部区 */

.content{

    width1250px;

    margin0 auto;

}

h3{

    font-size20px;

    color#000;

    height45px;

    line-height45px;

}

h3 span{

    font-size18px;

    color#636363;

    font-weightnormal;

}

.main_item_pass{

    

}

.main_item_ .red,

.main_item_ .orange,

.main_item_ .green{

    displayinline-block;

    width40px;

    height8px;

}

.main_item_ .red{

    background-colorred;

}

.main_item_ .orange,

.main_item_ .green{

    background-color:#dddddd;

}


.main{

    height600px;

    backgroundwhite;

    border-radius10px;

    border2px solid rgb(2511163);

    margin-bottom100px;

}

.main_title{

    background-colorrgb(2511163);

    color#fff;

    width100%;

    height40px;

    line-height40px;

    font-size20px;

    padding-left20px;

    border-radius6px;

}

.main_item{

    width60%;

    margin20px auto;

    height20px;

    line-height20px;

    font-size15px;

    positionrelative;

}

.main_item:nth-child(2){

    margin-top50px;

}

label span{

    displayinline-block;

    text-align-lastjustify;

    width60px;

}

.main_item-important{

    colorred;

}

.main_item input{

    positionabsolute;

    width210px;

    height20px;

    top50%;

    left15%;

    margin-top-10px;

}

select{

    positionabsolute;

    top50%;

    left15%;

    margin-top-10px;

    width210px;

}

.main_.item_ {

    width60%;

    height30px;

    border-bottom0.5px solid #6385d1;

    border-radius2px;

    font-size15px;

    colorrgb(2511163);

    letter-spacing2px;

    font-weightlighter;

    padding-left10px;

    margin0;

    margin-left5%;

}

.main_item .namerule{

    positionrelative;

    left350px;

    top-20px;

}

.main_item .namerule a{

    color#fb7403;

    text-decorationunderline;

    font-size15px;

}

.main_item .namerule a:hover+.namerule_{

    displayblock;

}

.main_item .namerule .namerule_{

    displaynone;

    width350px;

    height220px;

    positionabsolute;

    border1px solid blue;

    font-size10px;

    left95px;

    top15px;

    background#ffffff;

}

.main_item .namerule .namerule_ p{

    color#6c6c6c;

    margin5px 10px;

}


#main_end{

    text-aligncenter;

    height50px;

    line-height50px;

    width100%;

    letter-spacing2px;

}

#main_end #choose{

    margin-right10px;

}

#main_end #choose a{

    color#006ee1;

}

#main_end #handup{

    width230px;

    height38px;

    bordernone;

    background-color#fb7403;

    colorwhite;

    border-radius3px;

    margin-top35px;

}


/* 页脚区域 */

footer{

    displayblock;

    width100%;

    padding20px 0;

    background#eee;

    border-top2px solid rgb(36136201);

    text-aligncenter;

    color#ccc;

}

footer p{

    line-height40px;

}


/*获取元素节点*/

var tips = className("main_item_"),

    userAccount = byId("userAccount"),

    userPass = byId("userPass"),

    userPass_ = byId("userPass_"),

    userName = byId("userName"),

    nameRule = className("namerule")[0],

    information = byId("information"),

    email = byId("email"),

    phone = byId("telephone"),

    choose = byId("choose"),

    submit = byId("handup"),

    red = className("red")[0],

    orange = className("orange")[0],

    green = className("green")[0];

/*封装获取元素节点函数*/

function className(name) {

    return document.getElementsByClassName(name);

}

function byId(id) {

    return document.getElementById(id)

}

// 获取正则

var regexp = {

    userAccount: /^[a-z]\w{5,29}$/i,

    userPass: /^\S{6,20}$/,

    userName: /^[\u4e00-\u9fa5|a-zA-Z]{3,30}$/,

    idName: /^\d{17}[\dxX]$/,

    email: /^\w+@\w+\.\w{2,3}$/,

    phone: /^1[3|4|5|7|8][0-9]{9}$/

}

// 判断为真假

var test = {

    test1: false,

    test2: false,

    test3: false,

    test4: false,

    test5: false,

    test6: false,

}

// 用户名

userAccount.onblur = function () {

    if (!this.value) {

        tips[0].innerHTML = "6-30位字母、数字或'_',字母开头";

        tips[0].style.color = "red";

    } else {

        if (regexp.userAccount.exec(userAccount.value)) {

            tips[0].innerHTML = "用户名输入正确";

            tips[0].style.color = "green";

            test.test1 = true;

        } else {

            tips[0].innerHTML = "6-30位字母、数字或'_',字母开头";

            tips[0].style.color = "red";

        }

    }

}

// 变量接收密码框的值

var pwdValue = '密码框的值';

// 定义数量正则

var patt = /^\S{6,20}$/;

// 定义弱-中-强的正则

var pattern1 = /^\d{6,20}$|^[a-zA-Z]{6,20}$|^(\W|_){6,20}$/,

    pattern2 = /^[\da-zA-Z]{6,20}$|^[(\W|_)a-zA-Z]{6,20}$|^[(\W|_)\d]{6,20}$/,

    pattern3 = /^[(\W|_)\da-zA-Z]{6,20}$/;

// 登录密码

userPass.onblur = function () {

    //当数量不符合时的操作

    if (!patt.test(pwdValue)) {

        // 提示信息

        // tips[1].innerHTML = "6-20位字母、数字或'_',字母开头";

    } else {

        //当数量符合时的操作

        // 弱

        if (pattern1.test(pwdValue)) {

            //  改变后面小方块颜色

            red.style.backgroundColor = "red";

        } else if (pattern2.test(pwdValue)) {

            // 中

            //  改变后面小方块颜色

            orange.style.backgroundColor = "orange";

        } else if (pattern3.test(pwdValue)) {

            // 强

            //  改变后面小方块颜色

            green.style.backgroundColor = "green";

        }


    }

}








正在回答

登陆购买课程后可参与讨论,去登陆

2回答

同学你好,同学的代码,第三强度密码的正则书写是正确的,没有效果是因为方块样式设置的不对,建议:可以调整方块的样式,密码为弱时,设置第一个方块背景为红色,其他方块背景为灰色;密码为中时,设置第一个方块背景为红色,第二个方块背景为橙色,其他方块背景为灰色;密码为强时,设置第一个方块背景为红色,第二个方块背景为橙色,第三个方块背景为绿色

http://img1.sycdn.imooc.com//climg/5fb5cf2309a6a25f08490655.jpg
http://img1.sycdn.imooc.com//climg/5fb5cf860920a4d505710055.jpg

作业完成之后可以提交作业,批作业的老师会针对同学的问题给出详细的修改建议,并整理成文档发送给同学,祝学习愉快~
好帮手慕慕子 2020-11-18 11:01:31

同学你好,针对同学的问题解答如下:因为获取密码框输入的值不正确,所以无法实现效果。

建议修改:在失焦事件中,实时获取到输入的值。

http://img1.sycdn.imooc.com//climg/5fb48e8609fafde008610570.jpg

修改完之后,同学可以继续完善代码了,另外,作业完成之后可以提交作业,批作业的老师会针对同学的问题给出详细的修改建议,并整理成文档发送给同学,祝学习愉快~

  • 提问者 xiao肥瑞 #1
    第三强度密码怎么测试弄都弄不出来啊?求解
    2020-11-18 21:26:47
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
2.组件化网页开发
  • 参与学习           人
  • 提交作业       1121    份
  • 解答问题       14456    个

本阶段在运用JS实现动态网页开发的基础上,带你深入理解企业开发核心思想,完成一个企业级网页的开发,体验前端工程师的成就感。

了解课程
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师