js实现简单点名器
作者:互联网
用js简单实现了一个点名器
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>选妃了</title>
<style>
div {
background: pink;
width: 300px;
line-height: 200px;
text-align: center;
font-size: 50px;
margin-left: 600px;
}
button {
text-align: center;
font-size: 20px;
}
</style>
</head>
<body>
<div>
<span id="sp">选妃侍寝</span><br/>
<button onclick="fun01()" id="dian">翻牌了</button>
</div>
<script>
var arr = [
'古力娜扎',
'杨幂',
'张馨予',
'陈乔恩',
'庄达菲',
'陈钰琪',
'张雪迎',
'唐艺昕',
'赵珂',
'李允儿',
'UI'
];
var d1;
function fun() {
var i = Math.floor(Math.random() * (arr.length));
document.getElementById("sp").innerText = arr[i];
}
function fun01() {
var roll =document.getElementById("dian").innerText;
if(roll=="翻牌了"){
document.getElementById("dian").innerText="选择今夜侍寝";
d1 = setInterval("fun()", 10);
}else {
clearInterval(d1);
document.getElementById("dian").innerText="翻牌了";
}
}
</script>
</body>
</html>
标签:arr,点名,js,getElementById,innerText,简单,var,document,d1 来源: https://blog.csdn.net/lakewaterj/article/details/117259573