<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>onclick事件</title> <script type="text/javascript" src="$function.js"></script> </head> <body> <button style="background:red">红</button> <button style="background:yellow">黄</button> <button style="background:green">绿</button> <button style="background:blue">蓝</button> <button style="background:purple">紫</button> <div id="divid" style="width:500px;height:500px;background:black"> </div> </body> <script type="text/javascript"> var buttons = $imgs("button"); for(var i=0;i< buttons.length;i++){ buttons[i].onclick = function(){ $("divid").style.background = this.style.background; } } </script> </html>
onclick事件改变元素的背景颜色
最新推荐文章于 2023-04-14 10:35:45 发布