以前总是对jquery的尺寸稀里糊涂,有需要的可以看下下面的代码:

①页面布局如下:

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>jquery尺寸练习</title>
<script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js"></script>
<style>
.div1 {
width:360px;
height:300px;
background:pink;
border:2px solid #000;
margin:10px;
padding: 20px;
line-height: 24px;
}
</style>
</head>
<body>
<div class="div1"></div>
<button>显示 div 元素的尺寸</button>
<p>总结如下:</p>
<p>width() 方法设置或返回元素的宽度(不包括内边距、边框或外边距)。</p>
<p>height() 方法设置或返回元素的高度(不包括内边距、边框或外边距)。</p>
<p>innerWidth() 方法返回元素的宽度(包括内边距)。</p>
<p>innerHeight() 方法返回元素的高度(包括内边距)。</p>
<p>outerWidth() 方法返回元素的宽度(包括内边距和边框)。</p>
<p>outerHeight() 方法返回元素的高度(包括内边距和边框)。</p>
<p>outerHeight(true) 方法返回元素的高度(包括内边距和边框、外边距)。</p>
<p>outerHeight(true) 方法返回元素的高度(包括内边距和边框、外边距)。</p>
</body>
</html>
②javascript代码如下:
<script>
$(document).ready(function(){
$("button").click(function(){
var txt = '';
txt+="div 宽度:"+$(".div1").width()+"<br/>";
txt += "div 高度:"+$(".div1").height()+"<br/>";
txt +="div 宽度,包含内边距:"+$(".div1").innerWidth()+"<br>";
txt+="div 高度,包含内边距:"+$(".div1").innerHeight()+"<br>";
txt +="div 宽度,包含内边距和边框:"+$(".div1").outerWidth()+"<br>";
txt+="div 高度,包含内边距和边框:"+$(".div1").outerHeight()+"<br>";
txt +="div 宽度,包含内边距、边框和外边距:"+$(".div1").outerWidth(true)+"<br>";
txt+="div 高度,包含内边距、边框和外边距:"+$(".div1").outerHeight(true)+"<br>"; $(".div1").html(txt);
});
});
</script>
这次将尺寸理解明白,很感谢菜鸟教程这个网站,这是一个很不错的网站,适合新手入门。我很多不懂的东西都是通过这个网站学习的。另外附上一张尺寸图,如下:

最后,还是要多敲代码,即使是你能看懂的代码,有时候能看得懂当自己敲的时候不一定能敲出来。

												

关于jquery尺寸的总结的更多相关文章

  1. 实现文字自动横移--- jquery尺寸相关函数

    效果图: 一实现文字自动横移 <style type="text/css"> #demo {overflow:scroll;width:740px; } #indemo ...

  2. jQuery 基础(4)jQuery 尺寸

    jQuery 尺寸方法jQuery 提供多个处理尺寸的重要方法:width()height()innerWidth()innerHeight()outerWidth()outerHeight()jQu ...

  3. jQuery 尺寸

    通过 jQuery,很容易处理元素和浏览器窗口的尺寸. jQuery 尺寸 方法 jQuery 提供多个处理尺寸的重要方法: width() height() innerWidth() innerHe ...

  4. jquery尺寸和jQuery设置和获取内容方法

    一.jquery尺寸 jQuery 提供多个处理尺寸的重要方法: width()    设置或返回元素的宽度(不包括内边距.边框或外边距),括号中可填数值宽度参数,无单位 height()   设置或 ...

  5. jQuery尺寸

    jQuery 尺寸 jQuery width() 和 height() 方法 width() 方法设置或返回元素的宽度(不包括内边距.边框或外边距). height() 方法设置或返回元素的高度(不包 ...

  6. jQuery尺寸算法

    我们默认都统一是采用offsetWidth或者offsetHeight取值了,但我们知道关于这2个尺寸的算法是这样的: offsetWidth = border-left-width + paddin ...

  7. 图解JQUERY尺寸及位置定义

    最近在学习JQUERY的一些应用,接触到了JQUERY对于元素尺寸及位置定义,还有就是配合浏览器尺 寸及状态的计算所做出的一些动画特效.其实像这类JQUERY应用无外乎涉及这些属性的调用:innerH ...

  8. jQuery 尺寸 方法

    jQuery 提供多个处理尺寸的重要方法: width() height() innerWidth() innerHeight() outerWidth() outerHeight()

  9. jquery——尺寸

    1. 获取和设置元素的尺寸 2. 获取元素相对页面的绝对位置:offset() 这种方式增加的盒子不会对之前的结构产生影响 demo: <!DOCTYPE html> <html l ...

随机推荐

  1. shell 实例学习

    安装crond:yum install crontabs  (http://blog.163.com/victory_wxl/blog/static/14130530220115296180333/) ...

  2. PHPCMS快速建站系列之自定义分页函数

    内容分页的实现方法:{pc:content action="lists" catid="$catid" order="id DESC" nu ...

  3. leetcode day6

    [13]Roman to Integer Given a roman numeral, convert it to an integer. Input is guaranteed to be with ...

  4. --@angularJS--指令与指令之间的交互demo

    1.index.html: <!DOCTYPE HTML><html ng-app="app"><head>    <title>c ...

  5. HDU-1020-Encoding(水题,但题目意思容易搞错,英语的问题)

    题目链接 http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?pid=1000&ojid=0&cid=7996&h ...

  6. Canvas贝塞尔三级曲线

    两个控制点 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...

  7. sql数据库链接

    针对数据库只能链接计算机名称不能进行点(.)或者local本地链接的问题.主要会出现在刚装完系统的用户. 解决方法: 首先从SQL Server配置管理器中找到SQL Server网络配置的协议:TC ...

  8. 关于Vue.js 使用v-cloak后仍显示变量的解决方法

    v-cloak   这个指令是防止页面加载时出现 vuejs 的变量名而设计的,但有时候添加了这个指令仍会显示变量,这是怎么回事呢?. v-cloak 用法: HTML代码: <div v-cl ...

  9. 关于我的PP0.1聊天软件(客户端)

    登陆界面: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data ...

  10. jq-实战之表格筛选

    css部分 .select{background: #ccc} html部分 table width="> <thead> <th>姓名</th> ...