<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]="密碼強度差。 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.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> <BR> <BR><body> <BR>告訴你一個應有的網頁特效網址:<BR>http://www.jb51.net/list/list_43_1.htm<BR><BR> <form name="form1"> <BR><label for="pwd">使用者密碼 <A href="http://www.jb51.net/list/list_43_1.htm" target=_blank><input type="password" name="pwd" onKeyUp="chkpwd(this)" /> <div id="chkResult"></script> </div> <br> <br> <br>