<!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>
|