zoukankan      html  css  js  c++  java
  • js中的width问题

    1、在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>
    
    输出的结果是:200,220,240,260.



    <p id="p_obj" style=" 200px; padding:10px; border:10px solid blue; margin:10px;">This is a paragraph.</p> <button class="btn1">输出高度</button>

      

  • 相关阅读:
    no.5.print sum
    0.1 hint crack
    no.4 抽奖测试
    no2.crossdomain.xml批量读取(待完善)
    no.1
    day7-读写分离
    day6-主从
    day5-备份
    day4-用户授权
    Day3-体系结构+查询+导入/出
  • 原文地址:https://www.cnblogs.com/leyan/p/5112673.html
Copyright © 2011-2022 走看看