Result Size: 625 x 534
x
 
<!DOCTYPE html>
<html>
<head>
<style> 
#myDIV {
  border: 1px solid black;
  width: 300px;
  height: 300px;
  background: url('w3css.gif') no-repeat;
}
</style>
</head>
<body>
<h1>使用 JavaScript 更改背景大小</h1>
<p>单击“试一试”按钮放大 DIV 元素的背景尺寸:</p>
<button onclick="myFunction()">试一试</button>
<div id="myDIV">
  <h1>Hello</h1>
</div>
<script>
function myFunction() {
  document.getElementById("myDIV").style.backgroundSize = "300px 300px";
}
</script>
</body>
</html>