常用js代码
common-function-lib.js
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 }
作者:sy
出处:http://www.cnblogs.com/sydeveloper
QQ:522733724
本页版权归作者和博客园所有,欢迎转载,但未经作者同意必须保留此段声明,
且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利