zoukankan      html  css  js  c++  java
  • jquery获取元素的各种高度

    1、val()方法获取匹配元素集合中第一个元素的当前值,主要用于获取表单元素的值

      input/select/textarea      select中option设置select属性,val()方法返回option的值,如果select设置了multiple属性,val()方法返回的是一个数组

    2、height(),返回当前元素的高度(不含单位,不含边框,不含padding,不含margin),如果用css("height"),返回当前元素的高度,带单位,含边框,含padding,不含margin

    3、innerHeight()返回当前元素的高度(包括padding,但是不包括border,window和document不适用)

    4、outerheight()返回当前元素的高度(包括padding,border,默认不包括margin,设置outerHeight(true)则包括margin,)

    5、offset()获取元素相对文档(document)的位置(包括top和left)                  

    6、offsetParent(),获取当前元素最近的含有定位的祖先元素(祖先元素含有position:relative/absolute/fixed;将被找到)  

    7、position(),获取当前元素的位置,如果当前元素被定位,则获取当前元素相对定位的位置,如果没有被定位,则获取相对于文档(document)的定位,相当于offset()

    (如果当前元素有margin值,offset()会加上当前元素的margin值(认为margin值不是当前元素所在位置);position则把margin值计算在当前元素位置内,在计算位置是不加margin值)

    8、scrollLeft()获取滚动条(横滚)的位置;scrollTop()获取滚动条(竖滚)的位置

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             

  • 相关阅读:
    华为云-Centos7.6-部署elasticSearch7.7
    linux下安装nginx
    Redis5.0.8集群安装
    redis5.0.8单机安装
    Mybatis打印SQL
    PostgreSQL新手教程
    Debian install jdk7
    Debian install jre7
    Debian /etc/apt/sources.list
    安装J2EE的SDK报错:could not find the required version of the Java(TM)2 Runtime Environment in '(null)'的解决办法。
  • 原文地址:https://www.cnblogs.com/snly/p/6638986.html
Copyright © 2011-2022 走看看