【JavaScript】亂數產生密碼
<script type='text/javascript'> //字元成員 var keylist="abcdefghijklmnopqrstuvwxyz123456789" var temp='' //產生密碼 function generatepass(plength) { temp='' for (i=0;i<plength;i++) temp+=keylist.charAt(Math.floor(Math.random()*keylist.length)) return temp } function populateform(enterlength){ document.form1.output.value=generatepass(enterlength) } </script> 部份HTML碼: <html> <body> <form name=" form1 "> <input type="text" size=18 name=" output "> <input type="button" value="產生密碼" onClick=" populateform(this.form.thelength.value) "><br /> <b>密碼長度:</b> <input type="text" name=" thelength " size=3 value="6"> </form> </body> </html> 執行畫面: