<html>
<head>
<style>
img {
width: 200px;
height: 400px;
}
</style>
</head>
<body>
<h1>使用 JavaScript 更改 objectFit</h1>
<p>点击“试一试”按钮以剪切图像的边,同时保持纵横比:</p>
<img src="paris.jpg" alt="巴黎" id="myImg" width="400" height="300">
<br>
<button onclick="myFunction()">试一试</button>
<p>注意:Internet Explorer/Edge 15 或更早版本不支持 object-fit 属性。</p>
<script>
function myFunction() {
document.getElementById("myImg").style.objectFit = "cover";
}
</script>
</body>
</html>