这里是引用
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title>随机生成id</title>
<head>
<style>
#app{
text-align: center;
}
.num{
margin-right: 10px
}
button{
background: orange;
border: none;
box-shadow: 1px 1px 2px black;
padding: 5px;
margin: 0 5px;
}
#result>div{
padding: 10px;
border-bottom: 1px solid black;
text-align: center;
}
</style>
</head>
<body>
<div id='app'>
<button class="one">生成1个</button>
<button class="two">生成10个</button>
<button class="allClear">清除</button>
<div id="result">
</div>
</div>
</body>
<script>
function zero(time){
if (time<10) {
return time="0"+time;
}else{
return time;
}
}
function ran(){
var five="";
var now = new Date();
var y=now.getFullYear().toString();
var M=zero(now.getMonth()+1);
var d=zero(now.getDate())
var hour=zero(now.getHours().toString());
var m=zero(now.getMinutes().toString());
var s=zero(now.getSeconds().toString());
for (var i = 0; i < 5; i++) {
five+=Math.round(Math.random()*9)
}
var str = y + M+d+hour+m+s+five;
return str;
}
function allClear() {
t=0;
content.innerHTML=''
}
//
var content=document.getElementById('result');
var app=document.getElementById("app");
app.onclick=function(e) {
var target=e.target;
console.log(target.classList.value)
if (target.classList.value=='one') {
content.innerHTML+=`<div><div>${ran()}`
}else if (target.classList.value=='two') {
for (var i = 1; i < 11; i++) {
content.innerHTML+=`<div><div>${ran()}</div></div>`
}
}else if (target.classList.value=='allClear') {
allClear()
}
}
function allClear() {
content.innerHTML=''
}
</script>
</html>