<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="../node_modules/jquery/dist/jquery.js"></script>
</head>
<body>
<button>开始</button>
<input type="text">
<button>停止</button>
<script>
let arr=['张三','李四','王五','王大麻子','小明','小红','小黑','小花','李华','麦蔻','约翰','june',]
let timer = ''
let m = ''
$('button').eq(0).click(function(){
clearInterval(timer)
time(arr.length)
})
$('button').eq(1).click(function(){
clearInterval(timer)
})
function time(length){
timer =setInterval(function(){
m = parseInt(Math.random()*(length+1));
$('input').val(arr[m])
},30)
}
</script>
</body>
</html>
js实现随机点名
最新推荐文章于 2023-01-14 16:59:29 发布
这是一个简单的HTML页面,包含两个按钮和一个输入框。当点击'开始'按钮时,会每30毫秒随机从一个预定义的名字数组中选取一个显示在输入框里,直到点击'停止'按钮。该功能使用了jQuery库来实现交互效果。
摘要由CSDN通过智能技术生成