- 會有什麼語法使用JavaScript
- 改變身體的背景圖像如何修復線錯誤動態地改變一個div的背景圖像
y.style.background = '' + "url(1.jpg) no-repeat" + '';
<!DOCTYPE html>
<html>
<head>
<style>
body {
//this is the style for body tag
background: url("heart.png") no-repeat;
color: red;
}
</style>
</head>
<body>
<h3><p id="hello">This Is Heart.</p>
</h3>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var x = document.getElementById("hello"); //this is id of paragraph
var y = document.getElementsByTagName("body"); //id of background element
var z = document.getElementById('myImg');
y.style.background = '' + "url(1.jpg) no-repeat" + ''; //y error what will be the code to replace background-image of div
</script>
</body>
</html>
嘗試'style.backgroundImage =' – NewToJS