<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#div1 {
width: 100px;
height: 100px;
background: pink;
}
</style>
</head>
<body>
<!-- 需求 點擊按鈕 讓div顯示 -->
<!-- 點擊按鈕顯示div -->
<!-- <input type="button" value="點擊" onclick="div1.style.display='block'"> -->
<!-- <input type="button" value="點擊" onmouseover="document.getElementById('div1').style.width='200px';
document.getElementById('div1').style.height='200px';"> -->
<div id="div1" onmouseover="toBig()" onmouseout="tosmall()"></div>
<script>
/* 函數 */
function toBig() {
document.getElementById('div1').style.width = '200px';
document.getElementById('div1').style.height = '200px';
}
function tosmall() {
document.getElementById('div1').style.width = '100px';
document.getElementById('div1').style.height = '100px';
}
</script>
</body>
</html>
運行結果