HTML DOM background 屬性
定義和用法
background 屬性在一個聲明中設置所有的背景屬性。
語法:
Object.style.background=background-color background-image background-repeat background-attachment background-position
參數(shù) | 描述 | 值 |
---|---|---|
background-color | 設置元素的背景色。 |
|
background-image | 設置背景圖像。 |
|
background-repeat | 設置背景圖像是否及如何重復。 |
|
background-attachment | 背景圖像是否固定或者隨著頁面的其余部分滾動。 |
|
background-position | 設置背景圖像的起始位置。 |
|
實例
下面的例子改變了文檔背景的樣式:
<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>