GUID
GUID
2023-09-11 14:19:05 时间
1、
<script> $(function(){ $('#AdminId').change(function(){ //var data= $(this).val(); var guid = new GUID(); $('#ApiId').val(guid.newGUID()); $('#ApiKey').val(guid.newGUID()); }); }); function GUID() { this.date = new Date(); /* 判断是否初始化过,如果初始化过以下代码,则以下代码将不再执行,实际中只执行一次 */ if (typeof this.newGUID != 'function') { /* 生成GUID码 */ GUID.prototype.newGUID = function () { this.date = new Date(); var guidStr = ''; sexadecimalDate = this.hexadecimal(this.getGUIDDate(), 16); sexadecimalTime = this.hexadecimal(this.getGUIDTime(), 16); for (var i = 0; i < 9; i++) { guidStr += Math.floor(Math.random() * 16).toString(16); } guidStr += sexadecimalDate; guidStr += sexadecimalTime; while (guidStr.length < 32) { guidStr += Math.floor(Math.random() * 16).toString(16); } return this.formatGUID(guidStr); } /* * 功能:获取当前日期的GUID格式,即8位数的日期:19700101 * 返回值:返回GUID日期格式的字条串 */ GUID.prototype.getGUIDDate = function () { return this.date.getFullYear() + this.addZero(this.date.getMonth() + 1) + this.addZero(this.date.getDay()); } /* * 功能:获取当前时间的GUID格式,即8位数的时间,包括毫秒,毫秒为2位数:12300933 * 返回值:返回GUID日期格式的字条串 */ GUID.prototype.getGUIDTime = function () { return this.addZero(this.date.getHours()) + this.addZero(this.date.getMinutes()) + this.addZero(this.date.getSeconds()) + this.addZero(parseInt(this.date.getMilliseconds() / 10)); } /* * 功能: 为一位数的正整数前面添加0,如果是可以转成非NaN数字的字符串也可以实现 * 参数: 参数表示准备再前面添加0的数字或可以转换成数字的字符串 * 返回值: 如果符合条件,返回添加0后的字条串类型,否则返回自身的字符串 */ GUID.prototype.addZero = function (num) { if (Number(num).toString() != 'NaN' && num >= 0 && num < 10) { return '0' + Math.floor(num); } else { return num.toString(); } } /* * 功能:将y进制的数值,转换为x进制的数值 * 参数:第1个参数表示欲转换的数值;第2个参数表示欲转换的进制;第3个参数可选,表示当前的进制数,如不写则为10 * 返回值:返回转换后的字符串 */GUID.prototype.hexadecimal = function (num, x, y) { if (y != undefined) { return parseInt(num.toString(), y).toString(x); } else { return parseInt(num.toString()).toString(x); } } /* * 功能:格式化32位的字符串为GUID模式的字符串 * 参数:第1个参数表示32位的字符串 * 返回值:标准GUID格式的字符串 */ GUID.prototype.formatGUID = function (guidStr) { var str1 = guidStr.slice(0, 8) + '-', str2 = guidStr.slice(8, 12) + '-', str3 = guidStr.slice(12, 16) + '-', str4 = guidStr.slice(16, 20) + '-', str5 = guidStr.slice(20); return str1 + str2 + str3 + str4 + str5; } } } </script>
相关文章
- Is a GUID unique 100% of the time?
- Guid.ToString Method
- visual studio中csproj文件中的project guid改为小写 ( notepad++ 正则)
- 获得将要生成的资源的GUID
- 报错:Error, CM server guid updated, expected xxxxx, received xxxxx (未解决)
- 利用HttpWebRequest模拟表单提交 JQuery 的一个轻量级 Guid 字符串拓展插件. 轻量级Config文件AppSettings节点编辑帮助类
- Visual Studio 2017 - Windows应用程序打包成exe文件(2)- Advanced Installer 关于Newtonsoft.Json,LINQ to JSON的一个小demo mysql循环插入数据、生成随机数及CONCAT函数 .NET记录-获取外网IP以及判断该IP是属于网通还是电信 Guid的生成和数据修整(去除空格和小写字符)
- 利用反射快速给Model实体赋值 使用 Task 简化异步编程 Guid ToString 格式知多少?(GUID 格式) Parallel Programming-实现并行操作的流水线(生产者、消费者) c# 无损高质量压缩图片代码 8种主要排序算法的C#实现 (一) 8种主要排序算法的C#实现 (二)
- List<Guid?> a = new List<Guid?>();
- 工作总结 default Console.WriteLine(default(Guid));
- C# .net生成Guid的几种方式
- 在C#中GUID生成的四种格式
- GUID和UUID、CLSID、IID 区别及联系
- Oracle中实现SQL中的newid() 生成GUID
- 全局唯一ID(GUID)生成方案对比
- 全局唯一标识符(GUID)
- Guid is not updated for cluster with specified cluster id; need to wait for hosts in this cluster to come up
- oracle函数 sys_guid()
- Dynamic CRM 2015学习笔记(3)oData 查询方法及GUID值比较
- PostGIS中生成GUID字段值
- 【Loadrunner】解决客户端生成和引用GUID的方法
- 聚簇索引(聚集索引) 不可作用于GUID类型字段
- sqlserver中GUID的默认值设置
- sqlserver 中的GUID 全局唯一标识 -摘自网络
- Create GUID / UUID in JavaScript?
- java GUID生成器 产生随机GUID的方法
- NEWID()生成随机唯一GUID编码
- UUID 和 GUID