JS实现根据密码长度 显示安全条

原文:http://www.open-open.com/code/view/1431324883763

 

 

//根据密码长度显示安全条

                    <ul class="clear">
                    <li>密  码:</li>
                    <li> <input type="password" id="pwd" name="pwd" class="in" onKeyUp=pwStrength(this.value) onBlur=pw_y("pwd","pwd1")></li>
                    <li><em class="red">*</em></li>
                    <li class="i2 grey"><table border="0" bordercolor="#cccccc" style='display:marker'>
                    <tr align="center">
                        <td  id="strength_L"  bgcolor="#eeeeee">弱</td>
                        <td  id="strength_M" bgcolor="#eeeeee">中</td>
                        <td id="strength_H" bgcolor="#eeeeee">强</td>
                    <td align="left" >
                      <label id="pwd1">使用数字,字母,下划线,长度在 6 - 20 个字符之间</label></td>
                        </tr>
                    </table>                 
                    </li>
                    </ul>

function pwStrength(pwd){
    O_color="#eeeeee";
    L_color="#FF0000";
    M_color="#FF9900";
    H_color="#33CC00";
    if (pwd==null||pwd==''){
        Lcolor=Mcolor=Hcolor=O_color;
    }else{
        S_level=checkStrong(pwd);
        switch(S_level) {
            case 0:
                Lcolor=Mcolor=Hcolor=O_color;
            case 1:
                Lcolor=L_color;
                Mcolor=Hcolor=O_color;
                break;
            case 2:
                Lcolor=Mcolor=M_color;
                Hcolor=O_color;
                break;
            default:
                Lcolor=Mcolor=Hcolor=H_color;
            }
    }
    document.getElementById("strength_L").style.background=Lcolor;
    document.getElementById("strength_M").style.background=Mcolor;
    document.getElementById("strength_H").style.background=Hcolor;
    return;
} 
posted @ 2017-08-03 13:08  这个名字想了很久~  阅读(389)  评论(0编辑  收藏  举报