一想到古代的皇帝,后宫佳丽三千人,那个羡慕嫉妒啊!今天,你也可以拥有你的后宫佳丽,冲鸭!!!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h3>时间</h3>
<input type="text" value="" id="time">
<button onclick="startTime()">开始</button>
<button onclick="stopTime()">停止</button>
<h3>大型选秀抽奖现场</h3>
<button onclick="start1()">开始</button>
<button onclick="stop1()">停止</button>选中的人有:<input type="text" id="inp1" size="50"><button onclick="quchong()">去重</button>
<div id="div1" style="border: 1px solid red;width: 500px;height: 420px;background: url(../img/妲己.jpg) no-repeat;
background-size: 500px 420px">
</div>
</body>
<script>
let time = document.getElementById("time");
function startTime(){
s=setInterval(showTime,1000)
}
function showTime(){
let date = new Date();
date1=date.toLocaleString()
time.value=date1
// console.log(typeof(date))
// console.log(date.toLocaleString())
if(date.getSeconds()==0){
start1()
}
if(date.getSeconds()==5){
stop1()
}
}
function stopTime(){
clearInterval(s)
}
let img=['貂蝉','金莲','妲己','西施']
function start1() {
s=setInterval(showBeauty,100)
}
function showBeauty() {
ran=Math.floor(Math.random()*4)
div1.style.backgroundImage="url(../img/"+img[ran]+".jpg)"
}
function stop1() {
clearInterval(s)
inp1.value+=img[ran]+','
}
function quchong() {
arr1 = inp1.value.split(',');
// console.log(arr1);
let arr2=[]
for(let i=0;i<arr1.length-1;i++){
let flag=false //这里定义false为不存在
for(let name of arr2 ){
if(name==arr1[i]){
//如果有重复的,则定义为true,不加入新数组中
flag=true
break
}
}
if(!flag){ //如果不存在,才放入
arr2.push(arr1[i])
}
}
//将新数组加入到value中
console.log(arr2);
inp1.value=arr2+','
}
</script>
</html>