1、效果图
按钮生成随机图片和背景颜色
2、实现在js代码中绑定事件
<script>
//1、获取事件源对象,按钮
var button=document.querySelector("#btn_1");
var input_1=document.querySelector("#input_1");
//2、绑定事件
button.onclick=function(){
// alert("绑定成功");
addElement();
changeColor();
// **在随机生成图片的基础上,加上随机改变页面的背景色
function changeColor(){
var body=document.body;
var R=Math.random()*255;
var G=Math.random()*255;
var B=Math.random()*255;
body.style.backgroundColor="rgb("+R+","+G+","+B+")";
}
//3、addEventlistener
//添加事件监听器