手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >浅谈jQuery中height与width
浅谈jQuery中height与width
摘要:jquery中有三个获取element高度的方法,分别是:height(),innerHeight(),outerHeght(bool);同...

jquery中有三个获取element高度的方法,分别是:height(),innerHeight(),outerHeght(bool);同样对应的有三个获取element宽度的方法:width(),innerHeight(),outerHeight(bool),这三个方法分别对应怎样的元素属性,如下图所示:

浅谈jQuery中height与width1

从上面的图可以了解到:height()方法对应顶部style设置的width属性;

innerHeight()对应width+padding-top+padding-bottom;

outerHeight()对应width+padding-top+padding-bottom+border-top+border-bottom;

另外看到下面outerHeight与outerWidth的值不一样是由于outerWidth(bool)方法参数被设置成true,

这时会加上margin-top和margin-bottom;

即:outerWidth = width+padding-top+padding-bottom+border-top+border-bottom+margin-top+margin-bottom;

来个简单的示例吧

<html> <head> <script type="text/javascript" src="http://www.jb51.netjquery/jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $("#id200").width("300px"); }); }); </script> </head> <body> <div id="id100">HELLO</div> <div id="id200">W3SCHOOL</div> <button type="button">请点击这里</button> </body> </html>

以上所述就是本文的全部内容了,希望大家能够喜欢。

【浅谈jQuery中height与width】相关文章:

浅谈javascript中for in 和 for each in的区别

浏览器检测JS代码(兼容目前各大主流浏览器)

获得当前页面URL地址的三个JS代码

详解AngularJS中的http拦截

js生成验证码并直接在前端判断

浅谈javascript事件取消和阻止冒泡

详谈javascript中的cookie

浅谈jQuery中replace()方法

浅谈JavaScript中的Math.atan()方法的使用

javaScript中with函数用法实例分析

精品推荐
分类导航