<br> <form name="form1" action=""> <br> <br>输入密码: <input type="password" size="10" onkeyup="pwStrength(this.value)"><input type="password" size="10" onkeyup="pwStrength(this.value)">onBlur=pwStrength(this.value)> <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> <table width="217" border="1" cellpacing="0" cellpadding="1" bordercolor="#cccccc">height="23" style='display:inline '> <tr align="center" bgcolor="#eeeeee"> <script language="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>//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>//checkStrong函数 <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>return bitTotal(Modes); <BR>} <BR>//pwStrength函数 <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>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><td width="33%" id="strength_L">弱</td> <td width="33 %" id="strength_M">中</td> <td width="33%" id="strength_H">强</td> </tr> </table> </form>