jQuery中几个关于元素宽高方法的区别

几个关于元素宽高的方法

  • height():带参数设置,不带参数获取,参数是number类型
  • width():带参数设置,不带参数获取,参数是number类型
  • innerHeight() :内边距+内容的高度
  • innerWidth() :内边距+内容的宽度
  • outerHeight:上下内边距+内容+上下边框
  • outerWidth :左右内边距+内容+左右边框

案例测试:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>元素宽度与高度</title>
    <style type="text/css">
        #container{
            width:200px;
            height:200px;
            padding:20px;
            margin:30px;
            border:5px solid red;
        }
    </style>
    <script type="text/javascript" src="jquery-1.11.1.js"></script>
    <script type="text/javascript">
        $(function(){
            console.log("width():"+$("#container").width());
            console.log("height():"+$("#container").height());
            console.log("innerWidth()"+$("#container").innerWidth());
            console.log("innerHeight():"+$("#container").innerHeight());
            console.log("outerWidth():"+$("#container").outerWidth());
            console.log("outerHeight():"+$("#container").outerHeight());
        })
    </script>
</head>
<body>
    <div id = "container"></div>
</body>
</html>

运行结果:

mark

转载于:https://blog.51cto.com/11230344/2299943

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值