打开控制台,粘贴运行下面的代码
javascript
// chrome console generate guid var guid = (function() { function s4() { return Math.floor((1 + Math.random()) * 0x10000) .toString(16) .substring(1); } return function() { return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4(); };})();
每次需要guid 时,只需要执行guid()
方法即可。
如果你的数据表主键用的就是guid 这种类型,那么这个方法适合你。
可能还有其他情形会用上它,但我还不知道。