javascript 生成随机大小写的字母

时间:2014-02-21 04:27:11   收藏:0   阅读:407
/**
 * 返回一个随机的小写字母
 */
function getLowerCharacter(){
return getCharacter("lower");;
}


/**
 * 返回一个随机的大写字母
 */
function getUpperCharacter(){
return getCharacter("upper");;
}


/**
 * 返回一个字母
 */
function getCharacter(flag){
var character = "";
if(flag === "lower"){
character = String.fromCharCode(Math.floor( Math.random() * 26) + "a".charCodeAt(0));
}
if(flag === "upper"){
character = String.fromCharCode(Math.floor( Math.random() * 26) + "A".charCodeAt(0));
}
return character;
}

原文:http://blog.csdn.net/lts_cxl/article/details/19542255

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!