简体   繁体   English

document.body.style.backgroundImage与document.body.background

[英]document.body.style.backgroundImage vs document.body.background

两者有什么区别?

document.body.background refers to the deprecated background attribute of the body tag document.body.background是指body标签不推荐使用的background属性

http://www.w3schools.com/TAGS/att_body_background.asp http://www.w3schools.com/TAGS/att_body_background.asp

document.body.style.backgroundImage refers to the CSS background-image property of the body tag. document.body.style.backgroundImage引用body标记的CSS background-image属性。 It is equivalent to something like... 相当于...

body { 
  background-image:url('paper.gif');
}

Use the latter :-) 使用后者:-)

There's a third important entry to consider in addition to the depracated document.body.background and the way to change the CSS background image with document.body.style.backgroundImage .... You can use document.body.style.background to change all the background properties, including color image and repeat: 除了已取消使用的document.body.background以及使用document.body.style.backgroundImage ...更改CSS背景图像的方法之外,还有第三点要考虑。您可以使用document.body.style.background进行更改所有背景属性,包括彩色图像并重复:

document.body.style.background = "red";

or, to set more than one property 或者,设置多个属性

document.body.style.background="#0000FF url(example.jpg) repeat-x";

The above sets a background color, a background image, and sets a horizontal repeat for that image. 以上设置了背景色,背景图像,并为该图像设置了水平重复。

This is similar to the CSS: 这类似于CSS:

body {
    background:#0000FF url('example.jpg') repeat-x; }

( here's a little more info about document.body.style.background at W3Schools... I'm sure there's more complete info elsewhere though ) (这是W3Schools上有关document.body.style.background的更多信息。不过我敢肯定,其他地方还有更多完整信息)

document.body.background : You are not using CSS. document.body.background :您未使用CSS。

document.body.style.backgroundImage : you are setting using CSS. document.body.style.backgroundImage :您正在使用CSS进行设置。

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

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