jQuery 教程
- 第1节:jQuery 简介
- 第2节:jQuery 安装
- 第3节:jQuery 语法
- 第4节:jQuery 选择器
- 第5节:jQuery 事件
- 第6节:jQuery 效果 – 隐藏和显示
- 第7节:jQuery 效果 – 淡入淡出
- 第8节:jQuery 效果 – 滑动
- 第9节:jQuery 效果 – 动画
- 第10节:jQuery 效果 – 停止动画
- 第11节:jQuery Callback 方法
- 第12节:jQuery Chaining
- 第13节:jQuery 获取
- 第14节:jQuery 设置
- 第15节:jQuery 添加元素
- 第16节:jQuery 删除元素
- 第17节:jQuery CSS 类
- 第18节:jQuery css() 方法
- 第19节:jQuery 尺寸
- 第20节:jQuery 遍历
- 第21节:jQuery 遍历 – 祖先
- 第22节:jQuery 遍历 – 后代
- 第23节:jQuery 遍历 – 同胞(siblings)
- 第24节:jQuery 遍历 – 过滤
- 第25节:jQuery 选择器
- 第26节:jQuery 事件方法
- 第27节:jQuery 效果方法
- 第28节:jQuery HTML / CSS 方法
- 第29节:jQuery 遍历方法
- 第30节:jQuery AJAX 方法
- 第31节:jQuery 杂项方法
- 第32节:jQuery 属性
- 第33节:jQuery Validate插件(表单验证)
- 第34节:jQuery Accordion插件(折叠菜单)
- 第35节:jQuery Cookie 插件
- 第36节:jQuery Autocomplete插件(自动补齐)
- 第37节:jQuery Growl 插件(消息提醒)
- 第38节:jQuery Password Validation(密码验证)
- 第39节:jQuery Prettydate
- 第40节:jQuery Tooltip
- 第41节:jQuery Treeview
jQuery 尺寸
通过 jQuery,很容易处理元素和浏览器窗口的尺寸。
jQuery 尺寸 方法
jQuery 提供多个处理尺寸的重要方法:
- width()
- height()
- innerWidth()
- innerHeight()
- outerWidth()
- outerHeight()
jQuery 尺寸
jQuery width() 和 height() 方法
width() 方法设置或返回元素的宽度(不包括内边距、边框或外边距)。
height() 方法设置或返回元素的高度(不包括内边距、边框或外边距)。
下面的例子返回指定的 <div> 元素的宽度和高度:
实例
$("button").click(function(){
var txt="";
txt+="Width: " + $("#div1").width() + "</br>";
txt+="Height: " + $("#div1").height();
$("#div1").html(txt);
});
var txt="";
txt+="Width: " + $("#div1").width() + "</br>";
txt+="Height: " + $("#div1").height();
$("#div1").html(txt);
});
jQuery innerWidth() 和 innerHeight() 方法
innerWidth() 方法返回元素的宽度(包括内边距)。
innerHeight() 方法返回元素的高度(包括内边距)。
下面的例子返回指定的 <div> 元素的 inner-width/height:
实例
$("button").click(function(){
var txt="";
txt+="Inner width: " + $("#div1").innerWidth() + "</br>";
txt+="Inner height: " + $("#div1").innerHeight();
$("#div1").html(txt);
});
var txt="";
txt+="Inner width: " + $("#div1").innerWidth() + "</br>";
txt+="Inner height: " + $("#div1").innerHeight();
$("#div1").html(txt);
});
jQuery outerWidth() 和 outerHeight() 方法
outerWidth() 方法返回元素的宽度(包括内边距和边框)。
outerHeight() 方法返回元素的高度(包括内边距和边框)。
下面的例子返回指定的 <div> 元素的 outer-width/height:
实例
$("button").click(function(){
var txt="";
txt+="Outer width: " + $("#div1").outerWidth() + "</br>";
txt+="Outer height: " + $("#div1").outerHeight();
$("#div1").html(txt);
});
var txt="";
txt+="Outer width: " + $("#div1").outerWidth() + "</br>";
txt+="Outer height: " + $("#div1").outerHeight();
$("#div1").html(txt);
});
尝试一下
提示:outerWidth(true) 方法返回元素的宽度(包括内边距、边框和外边距);outerHeight(true) 方法返回元素的高度(包括内边距、边框和外边距)。