zoukankan      html  css  js  c++  java
  • jQuery 的 width()、height()、innerWidth()、innerHeight()、outWidth()、outHeight() 的区别

    jQuery width() 和 height() 方法

    width() 方法设置或返回元素的宽度(不包括内边距、边框或外边距)。

    height() 方法设置或返回元素的高度(不包括内边距、边框或外边距)。

    <!DOCTYPE html>
    <html>
    <head>
    <script src="/jquery/jquery-1.11.1.min.js">
    </script>
    <script>
    $(document).ready(function(){
      $("button").click(function(){
        var txt="";
        txt+="Width of div: " + $("#div1").width() + "</br>";
        txt+="Height of div: " + $("#div1").height();
        $("#div1").html(txt);
      });
    });
    </script>
    </head>
    <body>
    
    <div id="div1" style="height:100px;300px;padding:10px;margin:3px;border:1px solid blue;background-color:lightblue;"></div>
    <br>
    <button>显示 div 的尺寸</button>
    <p>width() - 返回元素的宽度。</p>
    <p>height() - 返回元素的高度。</p>
    
    </body>
    </html>

    结果:

    jQuery innerWidth() 和 innerHeight() 方法

    innerWidth() 方法返回元素的宽度(包括内边距)。

    innerHeight() 方法返回元素的高度(包括内边距)。

    <!DOCTYPE html>
    <html>
    <head>
    <script src="/jquery/jquery-1.11.1.min.js">
    </script>
    <script>
    $(document).ready(function(){
      $("button").click(function(){
        var txt="";
        txt+="Width of div: " + $("#div1").width() + "</br>";
        txt+="Height of div: " + $("#div1").height() + "</br>";
        txt+="Inner width of div: " + $("#div1").innerWidth() + "</br>";
        txt+="Inner height of div: " + $("#div1").innerHeight();
        $("#div1").html(txt);
      });
    });
    </script>
    </head>
    
    <body>
    <div id="div1" style="height:100px;300px;padding:10px;margin:3px;border:1px solid blue;background-color:lightblue;"></div>
    <br>
    
    <button>显示 div 的尺寸</button>
    <p>innerWidth() - 返回元素的宽度(包括内边距)。</p>
    <p>innerHeight() - 返回元素的高度(包括内边距)。</p>
    
    </body>
    </html>

    结果:

     

    jQuery outerWidth() 和 outerHeight() 方法

    outerWidth() 方法返回元素的宽度(包括内边距和边框)。

    outerHeight() 方法返回元素的高度(包括内边距和边框)。

    <!DOCTYPE html>
    <html>
    <head>
    <script src="/jquery/jquery-1.11.1.min.js">
    </script>
    <script>
    $(document).ready(function(){
      $("button").click(function(){
        var txt="";
        txt+="Width of div: " + $("#div1").width() + "</br>";
        txt+="Height of div: " + $("#div1").height() + "</br>";
        txt+="Outer width of div (margin included): " + $("#div1").outerWidth(true) + "</br>";
        txt+="Outer height of div (margin included): " + $("#div1").outerHeight(true);
        $("#div1").html(txt);
      });
    });
    </script>
    </head>
    <body>
    
    <div id="div1" style="height:100px;300px;padding:10px;margin:3px;border:1px solid blue;background-color:lightblue;"></div>
    <br>
    <button>显示 div 的尺寸</button>
    <p>outerWidth(true) - 返回元素的宽度(包括内边距、边框和外边距)。</p>
    <p>outerHeight(true) - 返回元素的高度(包括内边距、边框和外边距)。</p>
    
    </body>
    </html>

    结果:

  • 相关阅读:
    leetcode167 Two Sum II
    leetcode18 4Sum
    leetcode15 three sum
    leetcode-1-Two Sum
    SQL优化——select
    Hadoop 集群搭建
    虚拟机中的两台主机怎么相互拷贝文件
    doker5
    docker4
    docker3
  • 原文地址:https://www.cnblogs.com/snow1234/p/6832044.html
Copyright © 2011-2022 走看看