<div class="codetitle"> <span><a style="CURSOR: pointer" data="31504" class="copybut" id="copybut31504" onclick="doCopy('code31504')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code31504"> <br><script type="text/javascript"> <BR>//CharMode函数 <BR>//测试某个字符是属于哪一类. <BR>function CharMode(iN){ <BR>if (iN>=48 && iN <=57) //数字 <BR>return 1; <BR>if (iN>=65 && iN <=90) //大写字母 <BR>return 2; <BR>if (iN>=97 && iN <=122) //小写 <BR>return 4; <BR>else <BR>return 8; //特殊字符 <BR>} <br><br>//bitTotal函数 <BR>//计算出当前密码当中一共有多少种模式 <BR>function bitTotal(num){ <BR>modes=0; <BR>for (i=0;i<4;i++){ <BR>if (num & 1) modes++; <BR>num>>>=1; <BR>} <BR>return modes; <BR>} <br><br>//checkStrong函数 <BR>//返回密码的强度级别 <br><br>function checkStrong(sPW){ <BR>if (sPW.length<=4) <BR>return 0; //密码太短 <BR>Modes=0; <BR>for (i=0;i<sPW.length;i++){ <BR>//测试每一个字符的类别并统计一共有多少种模式. <BR>Modes|=CharMode(sPW.charCodeAt(i)); <BR>} <br><br>return bitTotal(Modes); <br><br>} <br><br>//pwStrength函数 <BR>//当用户放开键盘或密码输入框失去焦点时,根据不同的级别显示不同的颜色 <br><br>function pwStrength(pwd){ <BR>O_color="#eeeeee"; <BR>L_color="#FF0000"; <BR>M_color="#FF9900"; <BR>H_color="#33CC00"; <BR>if (pwd==null||pwd==''){ <BR>Lcolor=Mcolor=Hcolor=O_color; <BR>} <BR>else{ <BR>S_level=checkStrong(pwd); <BR>switch(S_level) { <BR>case 0: <BR>Lcolor=Mcolor=Hcolor=O_color; <BR>case 1: <BR>Lcolor=L_color; <BR>Mcolor=Hcolor=O_color; <BR>break; <BR>case 2: <BR>Lcolor=Mcolor=M_color; <BR>Hcolor=O_color; <BR>break; <BR>default: <BR>Lcolor=Mcolor=Hcolor=H_color; <BR>} <BR>} <br><br>document.getElementById("strength_L").style.background=Lcolor; <BR>document.getElementById("strength_M").style.background=Mcolor; <BR>document.getElementById("strength_H").style.background=Hcolor; <BR>return; <BR>} <BR></script> <br><br><br><form name="form1" action=""> <br>输入密码:<input type="password" size="10" onkeyup="pwStrength(this.value)" onblur="pwStrength(this.value)"> <br><br>密码强度: <br><table width="217" border="1" cellspacing="0" cellpadding="1" bordercolor="#cccccc" height="23" style="display:inline"> <br><tr align="center" bgcolor="#eeeeee"> <br><td width="33%" id="strength_L">弱</td> <br><td width="33%" id="strength_M">中</td> <br><td width="33%" id="strength_H">强</td> <br> </tr> <br> </table> <br> </form> <br> </div>