JavaScript 生成Guid函数


        //获取长度为32的Guid
        function getGuid32() {
            var rt_str = String.fromCharCode(65 + Math.floor(Math.random() * 26));
            for (i = 0; i < 31; ++i) {
                var num = Math.floor(Math.random() * (26 + 26 + 10));
                var ch_str;
                if (num < 10) {
                    ch_str = num.toString();
                }
                else if (num < 10 + 26) {
                    ch_str = String.fromCharCode(65 + num - 10);
                }
                else {
                    ch_str = String.fromCharCode(97 + num - 10 - 26);
                }
                rt_str += ch_str;
            }
            return rt_str;
        }
自己写的,获取长度为32的Guid

放在jQuery拓展方法里面吧

        jQuery.extend({
            getGuid32: function () {
                var rt_str = String.fromCharCode(65 + Math.floor(Math.random() * 26));
                for (i = 0; i < 31; ++i) {
                    var num = Math.floor(Math.random() * (26 + 26 + 10));
                    var ch_str;
                    if (num < 10) {
                        ch_str = num.toString();
                    }
                    else if (num < 10 + 26) {
                        ch_str = String.fromCharCode(65 + num - 10);
                    }
                    else {
                        ch_str = String.fromCharCode(97 + num - 10 - 26);
                    }
                    rt_str += ch_str;
                }
                return rt_str;
            }
        });

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM