简体   繁体   English

在javascript函数中更改文档背景图像

[英]Change document background image in javascript function

I want to change the html documents background image in a javascript function but I'm having some difficulty with it. 我想在javascript函数中更改html文档背景图像,但遇到了一些困难。 This is what I have: 这就是我所拥有的:

function changeBgImage(){

    document.background = "url('images/SecondBackground.png')";

}

But as I said, not working.. Any ideas? 但是正如我所说,这没有用。

采用

document.body.style.backgroundImage = "url('images/SecondBackground.png')";
function changeBGImage() {
  document.body.style.backgroundImage = "url(http://images.cheezburger.com/completestore/2010/7/9/fe8e91c5-c3f1-40cf-a034-983e8683ba73.jpg)";
};

That'll do it! 会做到的!

您很亲近,但也需要.body。

document.body.style.background = "url('images/SecondBackground.png')";

试试这个

              document.getElementById("id of body").setAttribute("style","background-url:'images/SecondBackground.png'")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM