<style>
#content span {
width: 60px;
height: 60px;
display: inline-block;
line-height: 60px;
text-align: center;
border: solid 3px red;
border-radius: 50%;
font-size: 30px;
}
#content span:last-child {
background-color: blue;
}
</style>
</head>
<body>
<div id="content"></div>
<button id="start">开始</button>
<button id="end">结束</button>
</body>
<script>
var content = document.querySelector('#content')
var start = document.querySelector('#start')
var end = document.querySelector('#end')
function getNums(start, end, many) {
var arr = []
while (arr.length < many) {
var num = Math.floor(Math.random() * (end - start + 1) + start)
num = num < 10 ? '0' + num : num
if (arr.indexOf(num) == -1) {
arr.push(num)
}
}
arr.sort(function (a, b) {
return a - b
})
return arr
}
getHtml()
function getHtml() {
var str = ''
var red = getNums(1, 33, 6) // 获取红球
var blue = red.concat(getNums(1, 16, 1)) // 获取篮球
for (var i in blue) {
str += `<span>${blue[i]}</span>`
}
content.innerHTML = str
}
var timer = null
start.onclick = function () {
timer = setInterval(getHtml, 50)
start.disabled = true
}
end.onclick = function () {
clearInterval(timer)
timer = null
start.disabled = false
}
</script>
网友评论