<!DOCTYPE html>
<!--原生js点击事件三种方式-->
<!--原生js取随机值-->
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<button onclick="show()" >方式1</button>
<button id = "btn2" >方式2</button>
<button id = "btn3" >方式3</button>
</body>
<script>
//元素动作
document.getElementById("btn2").onclick =show;
//事件监听
document.getElementById("btn3").addEventListener("click",show);
function show(){
console.log(randNum(1,5));
}
//随机取出min-max的数
function randNum(min,max){
return Math.floor(Math.random() * (max - min + 1)+1);
}
</script>
</html>