JavaScript 参考手册
Style backgroundImage 属性
设置背景图像
源代码:
点击运行 »
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>蜜蜂教程(mifengjc.com)</title> <script> function displayResult() { document.body.style.backgroundColor = "#f3f3f3"; document.body.style.backgroundImage = "url(" / examples / img_tree.png ")"; } </script> </head> <body> <h1>Hello World!</h1> <br> <button type="button" onclick="displayResult()">设置背景图片</button> </body> </html>
运行结果:
点击运行 »