var genSessionId = function(length){ var str = genSessionId.characters; if ( !"0"[0] ) { //fix IE67 str = str.split(""); } for(var i=0,id="",len = str.length;i < length;i++){ id += str[Math.floor(Math.random() * len)]; } return id; } genSessionId.characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'; alert(genSessionId(24))
转自:https://www.cnblogs.com/rubylouvre/archive/2010/07/19/1780432.html