jquery height width

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title></title>
        <script src="jquery-3.5.1.min.js" type="text/javascript" charset="utf-8"></script>

        <style type="text/css">
            #box {
                background-color: red;
                height: 100px;
                width: 100px;
                border: 10px solid yellow;
                margin: 10px;
            }
        </style>

        <script type="text/javascript">
            $(document).ready(function() {
                $("button").eq(0).click(function() {
                    $("#box").height(200);
                });
                $("button").eq(1).click(function() {
                    alert($("#box").height())
                });
                $("button").eq(2).click(function() {
                    $("#box").width(300);
                });
                $("button").eq(3).click(function() {
                    alert($("#box").width())
                });
            });
        </script>
    </head>
    <body>
        <button type="button">设置宽度</button>
        <button type="button">获取宽度</button>
        <button type="button">设置高度</button>
        <button type="button">获取高度</button>
        <div id="box">

        </div>
    </body>
</html>

image

posted @ 2020-10-22 09:57  thomas_blog  阅读(133)  评论(0编辑  收藏  举报