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

从上面的图可以了解到: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="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("#id200").width("300px");
});
});
</script>
</head>
<body>
<div id="id100" style="background:yellow;height:100px;width:100px">HELLO</div>
<div id="id200" style="background:yellow;height:100px;width:100px">W3SCHOOL</div>
<button type="button">请点击这里</button>
</body>
</html>
以上所述就是本文的全部内容了,希望大家能够喜欢。
相关文章
jQuery Validate 相关参数及常用的自定义验证规则
这篇文章主要介绍了jQuery Validate 相关参数及常用的自定义验证规则,非常不错,具有参考借鉴价值,需要的朋友可以参考下2017-03-03
jQuery中bind(),live(),delegate(),on()绑定事件方法实例详解
这篇文章主要介绍了jQuery中bind(),live(),delegate(),on()绑定事件方法,结合实例形式详细分析了bind(),live(),delegate(),on()方法绑定事件的具体使用技巧,并对比分析了四种方式的异同点,需要的朋友可以参考下2016-01-01
jQuery中attr()与prop()函数用法实例详解(附用法区别)
这篇文章主要介绍了jQuery中attr()与prop()函数用法,结合实例形式详细分析了attr()与prop()函数的使用技巧与相关注意事项,并附带了attr()与prop()函数用法的区别,需要的朋友可以参考下2015-12-12
jQuery EasyUI API 中文文档 - NumberBox数字框
jQuery EasyUI API 中文文档 - NumberBox数字框使用介绍,需要的朋友可以参考下。2011-10-10
firefox下jquery ajax返回object XMLDocument处理方法
使用jquery ajax处理struts2 返回json类型的时候,ajax执行成功返回结果为object XMLDocument,解决方法如下2014-01-01


最新评论