JS簡(jiǎn)單編號(hào)生成器實(shí)現(xiàn)方法(附demo源碼下載)
本文實(shí)例講述了JS簡(jiǎn)單編號(hào)生成器實(shí)現(xiàn)方法。分享給大家供大家參考,具體如下:
運(yùn)行效果截圖如下:
具體代碼如下:
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>編號(hào)生成器</title> </head> <body> <h1>編號(hào)生成器</h1> <div> 前綴:<input id="txtBegin" type="text" value="" /> 后綴:<input id="txtEnd" type="text" value="" /> <br /> 位數(shù):<input id="numCount" type="number" value="5" /> </div> <div style="margin:10px 0;"> <label><input type="radio" name="a1" onclick="fnNum();" checked /> 連續(xù)數(shù)字</label> <label><input type="radio" name="a1" onclick="fnPwd();" /> 隨機(jī)字符</label> </div> <div id="divNum"> 范圍:<input id="numBegin" type="number" value="0" /> ~ <input id="numEnd" type="number" value="100" /> <br /> 過(guò)濾字符:<input id="txtLimit" type="text" value="" /> 多個(gè)使用,號(hào)分割 </div> <div id="divPwd" style="display:none;"> <h3>0123456789 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ</h3> 包含字符:<input id="txtChar" type="text" value="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" style="width:600px;" /> <br /> 隨機(jī)生成個(gè)數(shù):<input id="txtCount" type="number" value="100" /> </div> <input type="button" value="生成號(hào)碼" onclick="run();" /> <span id="spanResult"></span> <hr /> <textarea id="txtContent" style="width:600px; height:500px;"> </textarea> <script> var boNum = true; function fnNum() { document.getElementById('divNum').style.display = 'block'; document.getElementById('divPwd').style.display = 'none'; boNum = true; } function fnPwd() { document.getElementById('divNum').style.display = 'none'; document.getElementById('divPwd').style.display = 'block'; boNum = false; } function run() { var str = ''; var txtCount = parseInt(document.getElementById('txtCount').value); var txtBegin = document.getElementById('txtBegin').value; var txtEnd = document.getElementById('txtEnd').value; var txtChar = document.getElementById('txtChar').value; var numCount = parseInt(document.getElementById('numCount').value); var numBegin = parseInt(document.getElementById('numBegin').value); var numEnd = parseInt(document.getElementById('numEnd').value); var txtLimit = document.getElementById('txtLimit').value; var limit = txtLimit.split(','); if (txtLimit == '') { limit = []; } var count = 0; if (!boNum) { var list = []; for (var i=0; i<txtCount; i++) { var s = ''; for (var j=0; j<numCount; j++) { s += txtChar.charAt(Math.floor(Math.random() * txtChar.length)); } var bo = false; for (var ii=0; ii<list.length; ii++) { if (list[ii] == s) { bo = true; alert(s); break; } } if (bo) continue; str += txtBegin + s + txtEnd + '\r\n'; list.push(s); count++; } } else { for (var i=numBegin; i<numEnd+1; i++) { var s = '' + i; s = (new Array( numCount - s.length + 1 ).join('0')) + s; var bo = false; for (var k=0; k<limit.length; k++) { if (s.indexOf(limit[k]) != -1) { bo = true; break; } } if (bo) continue; str += txtBegin + s + txtEnd + '\r\n'; count++; } } document.getElementById('txtContent').value = str; document.getElementById('spanResult').innerHTML = '生成了 ' + count + ' 個(gè)'; } </script> </body> </html>
完整實(shí)例代碼點(diǎn)擊此處本站下載。
更多關(guān)于JavaScript相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《JavaScript切換特效與技巧總結(jié)》、《JavaScript查找算法技巧總結(jié)》、《JavaScript動(dòng)畫特效與技巧匯總》、《JavaScript錯(cuò)誤與調(diào)試技巧總結(jié)》、《JavaScript數(shù)據(jù)結(jié)構(gòu)與算法技巧總結(jié)》、《JavaScript遍歷算法與技巧總結(jié)》及《JavaScript數(shù)學(xué)運(yùn)算用法總結(jié)》
希望本文所述對(duì)大家JavaScript程序設(shè)計(jì)有所幫助。
相關(guān)文章
表單input項(xiàng)使用label同時(shí)引用Bootstrap庫(kù)導(dǎo)致input點(diǎn)擊效果區(qū)增大問(wèn)題
這篇文章主要介紹了表單input項(xiàng)使用label,同時(shí)引用Bootstrap庫(kù),導(dǎo)致input點(diǎn)擊效果區(qū)增大問(wèn)題的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-10-10JavaScript保留兩位小數(shù)的2個(gè)自定義函數(shù)
這篇文章主要介紹了JavaScript保留兩位小數(shù)的2個(gè)自定義函數(shù),需要的朋友可以參考下2014-05-05- 下面就結(jié)合我自己的體會(huì)和所學(xué)習(xí)的東東和大家一起來(lái)學(xué)習(xí)在JS中如何使用面向?qū)ο蟮木幊獭?/div> 2011-08-08
JavaScript function函數(shù)種類詳解
這篇文章主要為大家詳細(xì)介紹了JavaScript function函數(shù)種類,包括普通函數(shù)、匿名函數(shù)、閉包函數(shù),感興趣的小伙伴們可以參考一下2016-02-02javascript實(shí)現(xiàn)禁止鼠標(biāo)滾輪事件
這篇文章主要介紹了javascript實(shí)現(xiàn)禁止鼠標(biāo)滾輪事件的相關(guān)資料,需要的朋友可以參考下2015-07-07JS call()及apply()方法使用實(shí)例匯總
這篇文章主要介紹了JS call()及apply()方法使用實(shí)例匯總,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-07-07用Greasemonkey 腳本收藏網(wǎng)站會(huì)員信息到本地
寫了個(gè)Greasemonkey腳本,可以收集世紀(jì)佳緣交友網(wǎng)會(huì)員搜索結(jié)果頁(yè)你喜歡的會(huì)員信息,把它們保存到本地HTML文件,以便日后查閱。為了避免肖像或隱私侵權(quán)問(wèn)題,本文附圖將作簡(jiǎn)單馬賽克處理。2009-10-10關(guān)于javascript中dataset的問(wèn)題小結(jié)
本文給大家介紹javascript中dataset的問(wèn)題詳解,包括dataset的基礎(chǔ)用法,使用dataset的作用以及dataset的基礎(chǔ)操作等相關(guān)問(wèn)題,對(duì)javascript dataset問(wèn)題感興趣的朋友一起學(xué)習(xí)吧2015-11-11js金額數(shù)字格式化實(shí)現(xiàn)代碼(加減逗號(hào)處理)
這篇文章主要介紹了js中將數(shù)字格式化為金額的方法,使用加減逗號(hào)處理金額,一個(gè)格式化金額的代碼,有需要的朋友參考下2014-04-04最新評(píng)論