javascript生成GUID的代码

时间:2021-09-17 21:48:32
<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>