JavaScript實現(xiàn)隨機(jī)五位數(shù)驗證碼
更新時間:2019年09月27日 15:50:12 作者:小羽向前跑
這篇文章主要為大家詳細(xì)介紹了JavaScript實現(xiàn)隨機(jī)五位數(shù)驗證碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了js實現(xiàn)隨機(jī)五位數(shù)驗證碼的具體代碼,供大家參考,具體內(nèi)容如下
功能展示:
點擊按鈕,隨機(jī)生成數(shù)字+大小寫字母驗證碼
所有代碼:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>隨機(jī)生成驗證碼</title> </head> <style> /*驗證碼*/ .upload-awrp { overflow: hidden; margin: 120px 0; } .code { font-family: Arial; font-style: italic; font-size: 30px; border: 0; padding: 2px 3px; letter-spacing: 3px; font-weight: bolder; float: left; cursor: pointer; width: 150px; height: 60px; line-height: 60px; text-align: center; vertical-align: middle; border: 1px solid #6D6D72; } </style> <body> <!--隨機(jī)驗證碼--> <div id="check-code" style="overflow: hidden;"> <div class="code" id="data_code"></div> </div> <script src="js/jquery.min.js"></script> <script type="text/javascript"> $.fn.code_Obj = function(o) { var _this = $(this); var options = { code_l: o.codeLength,//驗證碼長度 codeChars: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' ], codeColors: ['#f44336', '#009688', '#cddc39', '#03a9f4', '#9c27b0', '#5e4444', '#9ebf9f', '#ffc8c4', '#2b4754', '#b4ced9', '#835f53', '#aa677e'], code_Init: function() { var code = ""; var codeColor = ""; var checkCode = _this.find("#data_code"); for(var i = 0; i < this.code_l; i++) { var charNum = Math.floor(Math.random() * 52); code += this.codeChars[charNum]; } for(var i = 0; i < this.codeColors.length; i++) { var charNum = Math.floor(Math.random() * 12); codeColor = this.codeColors[charNum]; } console.log(code); if(checkCode) { checkCode.css('color', codeColor); checkCode.className = "code"; checkCode.text(code); checkCode.attr('data-value', code); } } }; options.code_Init();//初始化驗證碼 _this.find("#data_code").bind('click', function() { options.code_Init(); }); }; $('#check-code').code_Obj({ codeLength: 5 }); </script> </body> </html>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JavaScript實現(xiàn)把rgb顏色轉(zhuǎn)換成16進(jìn)制顏色的方法
這篇文章主要介紹了JavaScript實現(xiàn)把rgb顏色轉(zhuǎn)換成16進(jìn)制顏色的方法,涉及javascript實現(xiàn)數(shù)制轉(zhuǎn)換的相關(guān)技巧,需要的朋友可以參考下2015-06-06JavaScript轉(zhuǎn)換數(shù)據(jù)庫DateTime字段類型方法
下面小編就為大家?guī)硪黄狫avaScript轉(zhuǎn)換數(shù)據(jù)庫DateTime字段類型方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-06-06BootStrap學(xué)習(xí)筆記之nav導(dǎo)航欄和面包屑導(dǎo)航
這篇文章主要介紹了BootStrap學(xué)習(xí)筆記之nav導(dǎo)航欄和面包屑導(dǎo)航的相關(guān)資料,需要的朋友可以參考下2017-01-01