HTML DOM backgroundImage 屬性
定義和用法
backgroundImage 屬性設置元素的背景圖像。
語法:
Object.style.backgroundImage=url(URL)|none
參數(shù) | 描述 |
---|---|
url(URL) | 圖像的路徑。 |
none | 無背景圖像。 |
提示和注釋
提示:請設置一種可用的背景顏色,這樣的話,假如背景圖像不可用,頁面也可獲得良好的視覺效果。
實例
本例設置了背景圖像:
<html>
<head>
<script type="text/javascript">
function changeStyle()
{
document.body.style.backgroundColor="#FFCC80";
document.body.style.backgroundImage="url(bgdesert.jpg)";
}
</script>
</head>
<body>
<input type="button" onclick="changeStyle()"
value="Set background image" />
</body>
</html>