這裏的HTML如何更改使用javascript的網站上的背景圖像位置?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<script type="text/javascript" src="temp.js">
</script>
<style type="text/css">
body {
background-image: url(image.jpg);
background-repeat: no-repeat;
background-position: 0px 100px;
}
</style>
<body>
<p>This is a test paragraph to fill space</p>
<input type="button" onClick="size()"/>
</body>
</html>
和JavaScript
function size() {
var body = document.getElementsByTagName("body");
body.style.backgroundPosition: "0px 30px";
}
但由於某些原因,當我按一下按鈕沒有任何反應。任何人都知道什麼不起作用?
這是簡單的使用只是'document.body'來指代'body'元素。 –
@ JukkaK.Korpela:謝謝!更新。 –