标签:
Javascript实现页面背景颜色的改变
<!DOCTYPE html> <html> <head> <title></title> </head> <body> <button style="background:red">red</button> <button style="background:green">green</button> <button style="background:blue">blue</button> <button style="background:aqua">aqua</button> <button style="background:pink">pink</button> <script type="text/javascript"> var node=document.getElementsByTagName(‘button‘); for(var i=0;i<node.length;i++){ node[i].onclick=function(){ document.documentElement.style.background=this.style.background; } } </script> </body> </html>
//背景图片的改变
<!DOCTYPE html> <html> <head> <title></title> </head> <body> <button style="background:url(‘1.jpg‘)">背景1</button> <button style="background:url(‘2.jpg‘)">背景2</button> <button style="background:url(‘3.jpg‘)">背景3</button> <script type="text/javascript"> var node=document.getElementsByTagName(‘button‘); for(var i=0;i<node.length;i++){ node[i].onclick=function(){ document.documentElement.style.background=this.style.background; } } </script> </body> </html>
//附用到的背景图3张
标签:
原文地址:http://my.oschina.net/dongdong11019/blog/499273