經常使用js代碼

common-function-lib.jsdom

 1 /*產生隨機顏色*/
 2 function randomColor() {
 3     var rand = Math.floor(Math.random() * 0xFFFFFF).toString(16);
 4     if (rand.length == 6) {
 5         return rand;
 6     } else {
 7         return randomColor();
 8     }
 9 }
10 /* 獲取url中"?"符後的參數 */
11 function getRequest() {
12     var url = location.search; // 獲取url中"?"符後的字串
13     var theRequest = new Object();
14     if (url.indexOf("?") != -1) {
15         var str = url.substr(1);
16         strs = str.split("&");
17         for ( var i = 0; i < strs.length; i++) {
18             theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
19         }
20     }
21     return theRequest;
22 }
23 /*生成驗證碼*/
24 function createCode() {
25     var code = "";
26     var codeLength = 4;//驗證碼的長度  
27     var random = new Array(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',
28     'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
29     for (var i = 0; i < codeLength; i++) {
30         var index = Math.floor(Math.random() * 36);
31         code += random[index];
32     }
33 }
相關文章
相關標籤/搜索