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>

 

你可能感兴趣的:(JavaScript)