• jquery中innerWidth(),outerWidth(),outerWidth(true)和width()的区别


    jquery中innerWidth(),outerWidth(),outerWidth(true)和width()的区别

    var a = 元素本身的宽度;

    width() = a;

    innerWidth() = a+padding;

    outerWidth() = a+padding+border;

    outerWidth(true) = a+padding+border+margin;

    在jQuery中,
    width()方法用于获得元素宽度;
    innerWidth()方法用于获得包括内边界(padding)的元素宽度,
    outerWidth()方法用于获得包括内边界(padding)和边框(border)的元素宽度,
    如果outerWidth()方法的参数为true则外边界(margin)也会被包括进来,即获得包括外边框(margin)、内边界(padding)和边框(border)的元素宽度。
    同理,innerHeight方法与outerHeight方法也是用同样的方法计算相应的高度。
    所以说:对于同一个元素应该是:
    width()<=innerWidth()<=outerWidth()<=outerWidth(true);


    举个例子:
    <script type="text/javascript">
    $(document).ready(function(){
    $(".btn1").click(function(){
    var obj=$("#p_obj");
    alert(obj.width());
    alert(obj.innerWidth());
    alert(obj.outerWidth());
    alert(obj.outerWidth(true));
    });
    });
    </script>
    <p id="p_obj" style=" 200px; padding:10px; border:10px solid blue; margin:10px;">This is a paragraph.</p>
    <button class="btn1">输出高度</button>

    输出的结果分别是 200px, 220px, 240px, 260px.
  • 相关阅读:
    Django contenttypes组件
    Django admin组件使用
    Django 信号
    Django 中间件
    Django 分页组件替换自定义分页
    Django ORM操作补充
    Django ORM 操作2 增删改
    Django 序列化
    JavaScript
    CSS 属性
  • 原文地址:https://www.cnblogs.com/keyi/p/5933981.html
Copyright © 2020-2023  润新知