前端學習(1617):前端系列實戰課程之函數和變量

<!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>

運行結果

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章