javascript生成GUID的代码

<script type="text/javascript">
    var Guid = function(){};
    Guid.prototype = {
        S4:function(){
            return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
        },
        NewGuid: function() {
            return (this.S4() + this.S4() + "-" + this.S4() + "-" + this.S4() + "-" + this.S4() + "-" + this.S4() + this.S4() + this.S4());
        }
    };
    var guid = new Guid();
    document.write(guid.NewGuid());
</script>

 

posted @ 2013-08-16 16:56  屌丝大叔的笔记  阅读(354)  评论(0编辑  收藏  举报