make a lottery button

make a lottery button

<button id="btn">抽奖</button>
//准备一个数组,存放姓名
			var  arr=['周公','干将莫邪','赵子龙','张飞','司马懿']
			//随机0-5之间的一个整数,作为下标找元素
			btn.onclick=function(){
    
    
				//0--1*10(数组长度)  0.x----9.x  向下取整
				var	n=Math.floor(Math.random()*arr.length)
				console.log(n)
				//获取随机元素
				cont.innerHTML = arr[n]
			}

Guess you like

Origin blog.csdn.net/m0_65792710/article/details/126822241