Home > Web Front-end > JS Tutorial > body text

Example of method to generate UUID using JS_javascript skills

WBOY
Release: 2016-05-16 15:07:11
Original
1179 people have browsed it

Example of method to generate UUID using JS

<!DOCTYPE html>
<html>
<head>
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js">
</script>
<script>
var id=getUuid();

$(document).ready(function(){
 $("p").click(function(){
  alert(id);
 });
});
  
function getUuid(){
  var len=32;//32长度
  var radix=16;//16进制
  var chars='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');var uuid=[],i;radix=radix||chars.length;if(len){for(i=0;i<len;i++)uuid[i]=chars[0|Math.random()*radix];}else{var r;uuid[8]=uuid[13]=uuid[18]=uuid[23]='-';uuid[14]='4';for(i=0;i<36;i++){if(!uuid[i]){r=0|Math.random()*16;uuid[i]=chars[(i==19)&#63;(r&0x3)|0x8:r];}}}
  return uuid.join('');
}  
  
</script>
</head>
<body>

<p>点我,生成UUID。</p>

</body>
</html>
Copy after login

The above example of how to generate UUID using JS is all the content shared by the editor. I hope it can give you a reference, and I hope you will support Script Home.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!