<div class="codetitle"> <span><a style="CURSOR: pointer" data="70037" class="copybut" id="copybut70037" onclick="doCopy('code70037')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code70037"> <br> <br> <br><title>密码强度检测效果</title> <br><script type="text/javascript"> <BR>function chkpwd(obj){ <BR>var t=obj.value; <BR>var id=getResult(t); <BR>//定义对应的消息提示 <BR>var msg=new Array(4); <BR>msg[0]="密码过短。"; <BR>msg[1]="密码强度差。"; <BR>msg[2]="密码强度良好。"; <BR>msg[3]="密码强度高。"; <BR>var sty=new Array(4); <BR>sty[0]=-45; <BR>sty[1]=-30; <BR>sty[2]=-15; <BR>sty[3]=0; <BR>var col = new Array(4); <BR>col[0] = "gray"; <BR>col[1] = "#50AEDD"; <BR>col[2] = "#FF8213"; <BR>col[3] = "green"; <BR>//设置显示效果 <BR>var bImg="http://download.jz123.cn/sc/pwdlen_dSIPeEGQWxfO.gif" //一张显示用的图片 <BR>var sWidth=300; <BR>var sHeight=15; <BR>var Bobj=document.getElementById("chkResult"); <BR>Bobj.style.fontSize="12px"; <BR>Bobj.style.color=col[id]; <BR>Bobj.style.width=sWidth + "px"; <BR>Bobj.style.height=sHeight + "px"; <BR>Bobj.style.lineHeight=sHeight + "px"; <BR>Bobj.style.background="url(" + bImg + ") no-repeat left " + sty[id] + "px"; <BR>Bobj.style.textIndent="20px"; <BR>Bobj.innerHTML="检测提示:" + msg[id]; <BR>} <BR>//定义检测函数,返回0/1/2/3分别代表无效/差/一般/强 <BR>function getResult(s){ <BR>if(s.length < 4){ <BR>return 0; <BR>} <BR>var ls = 0; <BR>if (s.match(/[a-z]/ig)){ <BR>ls++; <BR>} <BR>if (s.match(/[0-9]/ig)){ <BR>ls++; <BR>} <BR>if (s.match(/(.[^a-z0-9])/ig)){ <BR>ls++; <BR>} <BR>if (s.length < 6 && ls > 0){ <BR>ls--; <BR>} <BR>return ls <BR>} <BR></script> <br> <br> <br>告诉你一个应有尽有的网页特效网址:<a href="http://www.jb51.net/list/list_43_1.htm" target="_blank">http://www.jb51.net/list/list_43_1.htm</a><br><form name="form1"> <br><label for="pwd">用户密码</label> <br><input type="password" name="pwd" onkeyup="chkpwd(this)"> <br><div id="chkResult"></div> <br> </form> <br> <br> <br> </div>