jQuery之css属性width()、innerWidth()、outerWidth()、outerWidth(true)

width()和innerWidth()

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <style>
        #demo{
            width: 100px;
            height: 100px;
            padding: 20px;
            margin: 30px;
            border: 10px solid red;
            background: blueviolet;
        }
    </style>
    <title>Document</title>
</head>
<body>

    <div id="demo">


    </div>
    
    <script src="../jqueryFile/jquery-3.4.1.js"></script>
    <script>
        // 元素本身的宽度
        console.log( $("#demo").width() );      // 100
        // 元素本身的宽度 + padding
        console.log( $("#demo").innerWidth());  // 140
        // 元素本身的宽度 + padding + border
        console.log( $("#demo").outerWidth());  // 160
        // 元素本身的宽度 + padding + border + margin
        console.log( $("#demo").outerWidth(true)); //220

    </script>
</body>
</html>

TIM截图20190703192049.png
https://www.cnblogs.com/calin/p/4881627.html

Last modification:July 3rd, 2019 at 07:31 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment