HTML DOM background 屬性
定義和用法
background 屬性在一個(gè)聲明中設(shè)置所有的背景屬性。
語法:
Object.style.background=background-color background-image background-repeat background-attachment background-position
參數(shù) | 描述 | 值 |
---|---|---|
background-color | 設(shè)置元素的背景色。 |
|
background-image | 設(shè)置背景圖像。 |
|
background-repeat | 設(shè)置背景圖像是否及如何重復(fù)。 |
|
background-attachment | 背景圖像是否固定或者隨著頁面的其余部分滾動(dòng)。 |
|
background-position | 設(shè)置背景圖像的起始位置。 |
|
實(shí)例
下面的例子改變了文檔背景的樣式:
<html>
<head>
<script type="text/javascript">
function setStyle()
{
document.body.style.background="#FFCC80 url(bgdesert.jpg) repeat-y";
}
</script>
</head>
<body>
<input type="button" onclick="setStyle()"
value="Set background style" />
</body>
</html>