【jQuery】jQuery API 过 一 遍
closest, parents
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<ul id="one" class="level-1">
<li class="item-i">I</li>
<li id="ii" class="item-ii">II
<ul class="level-2">
<li class="item-a">A</li>
<li class="item-b">B
<ul class="level-3">
<li class="item-1">1</li>
<li class="item-2">2</li>
<li class="item-3">3</li>
</ul>
</li>
<li class="item-c">C</li>
</ul>
</li>
<li class="item-iii">III</li>
</ul>
<script src="http://upcdn.b0.upaiyun.com/libs/jquery/jquery-2.0.3.min.js"></script>
<script>
// closest 从元素本身开始,在DOM 树上逐级向上级元素匹配,并返回最先匹配的祖先元素
console.log($('.item-a').closest('ul').attr('class')) // level-2
console.log($('.item-a').closest('li').attr('class')) // item-a
console.log($('.item-a').parents().length) // 5
</script>
</body>
</html>
offset, offsetParent, position
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
*{margin:0;padding:0;}
div{padding:10px;}
#box1,#container1{background:red;}
#box2,#container2{background:green;}
#box3,#container3{background:gray;}
#container2{position:relative;}
</style>
</head>
<body>
<div id="box1">
<div id="box2">
<div id="box3">box3</div>
</div>
</div>
<div id="container1">
<div id="container2">
<div id="container3">container3</div>
</div>
</div>
<script src="http://static01.baomihua.com/js/lib/jquery-1.4.4.min.js?t=20120926.js"></script>
<script>
/**
* offset() 在匹配的元素集合中,获取的第一个元素的当前坐标,或设置每一个元素的坐标,坐标相对于文档
* offsetParent() 获取离指定元素最近的含有定位信息的祖先元素
* position() 获取匹配元素中第一个元素的当前坐标,相对于offset parent的坐标。( 译者注:offset parent指离该元素最近的而且被定位过的祖先元素 )
*/
console.log($('#box3').offset())
console.log($('#box3').offsetParent())
console.log($('#box3').position())
console.log($('#container3').offset())
console.log($('#container3').offsetParent())
console.log($('#container3').position())
</script>
</body>
</html>
width, innerWidth, outerWidth, height, innerHeight, outerHeight
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
#box1{background:gray;padding:10px;margin:10px;border:10px solid red;width:100px;height:100px;}
</style>
</head>
<body>
<div id="box1" style="color:red;">box1</div>
<script src="http://static01.baomihua.com/js/lib/jquery-1.4.4.min.js?t=20120926.js"></script>
<script>
/**
* .css('height') 和 .height()之间的区别是后者返回一个没有单位的数值
* box-sizing: border-box
* width() height()
* innerWidth() innerHeight() 包括padding
* outerWidth([includeMargin]) outerHeight([includeMargin]) 包括padding, border, [margin]
*/
console.log($('#box1').css('height'), $('#box1').height())
console.log(document.getElementById('box1').offsetHeight)
</script>
</body>
</html>
【jQuery】jQuery API 过 一 遍的更多相关文章
- JavaScript强化教程——jQuery UI API 类别
---恢复内容开始--- 主要介绍:JavaScript强化教程—— jQuery UI API 类别 jQuery UI 在jQuery 内置的特效上添加了一些功能.jQuery UI 支持颜色动 ...
- jQuery EasyUI API 中文文档 - ComboGrid 组合表格
jQuery EasyUI API 中文文档 - ComboGrid 组合表格,需要的朋友可以参考下. 扩展自 $.fn.combo.defaults 和 $.fn.datagrid.defaults ...
- jQuery EasyUI API 中文文档 - ValidateBox验证框
jQuery EasyUI API 中文文档 - ValidateBox验证框,使用jQuery EasyUI的朋友可以参考下. 用 $.fn.validatebox.defaults 重写了 d ...
- jQuery EasyUI API 中文文档
http://www.cnblogs.com/Philoo/tag/jQuery/ 共2页: 1 2 下一页 jQuery EasyUI API 中文文档 - 树表格(TreeGrid) 风流涕淌 ...
- jQuery DataTable-JavaScript API
虽然大多数时候你的Javascript交互将通过使用datatable初始化对象作为描述在使用这个网站的部分,有时,你会发现它有用一些外部控制表.可以使用以下函数从jQuery.dataTable对象 ...
- jQuery.localStorage() - jQuery SDK API
jQuery.localStorage() - jQuery SDK API jQuery.localStorage() From jQuery SDK API Jump to: navigati ...
- jQuery.mobile.changePage() | jQuery Mobile API Documentation
jQuery.mobile.changePage() | jQuery Mobile API Documentation <script> $.mobile.changePage( &qu ...
- JQuery常用API 核心 效果 JQueryHTML 遍历 Event事件
JQuery 常用API 参考资料:JQuery 官网 jQuery API 中文文档 核心 jQuery 对象 jQuery() 返回匹配的元素集合,无论是通过在DOM的基础上传递的参数还是创建 ...
- jquery 常用api 小结2
*一)jQuery常用方法API实战 (1)DOM简述与分类 A)DOM是一种标准,它独立于平台,语言,浏览器. B)如果项目中,你完全按照DOM标准写代码,你就能在各大主流的浏览器中操作标准控件. ...
- jQuery常用API之jQuery选择器
3.jQuery常用API 3.1 jQuery选择器 3.1.1 jQuery基础选择器 原生JS获取元素的方式很多.很杂,而且兼容性情况不一致,因此jQuery给我做了封装,是获取元素统一了标准 ...
随机推荐
- ORACLE 11G EXP导出空表方法
EXP在导出11G的库的时候,与过去10G,9I的版本有很大的差别. 就是没有数据的表是不会分配空间的. 从Oracle 11.2.0.1版本开始,Oracle又提供了一种新的空间分配方法: Crea ...
- zoj 2112 Dynamic Rankings(主席树&动态第k大)
Dynamic Rankings Time Limit: 10 Seconds Memory Limit: 32768 KB The Company Dynamic Rankings has ...
- Swift: 类与结构体
对比类与结构体 类与结构体有许多的相同点,它们都可以: 定义属性来存储值: 定义方法来提供功能: 定义下标操作: 定义初始化函数: 扩展它的默认的实现: 遵从协议: 类有一些额外的能力,但是结构体没有 ...
- static对象的高级用法
1. 函数里static对象是local的,其他如全局对象,类里的static对象都是非local的,会在程序初始化中提前创建 2. 非local的对象的创建无法确定先后次序,但能保证在main函数前 ...
- [转] boost.circular_buffer简介
http://www.cnblogs.com/TianFang/archive/2013/02/05/2892503.html 很多时候,我们需要在内存中记录最近一段时间的数据,如操作记录等.由于这部 ...
- GNU Make----Core Automatic Variables
$@ 表示规则的目标文件名.如果目标是一个文档文件(Linux中,一般称.a 文件为 文档文件,也称为静态库文件),那么它代表这个文档的文件名.在多目标模式 规则中,它代表的是哪个触发规则被执行的目标 ...
- 线程、委托、lambda运算符的简单示例
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- Java基础知识强化之IO流笔记16:IO流的概述和分类
1. IO流的分类 流向: (1)输入流:读取数据到内存 (2)输出流:写入数据到硬盘(磁盘) 操作的数据类型: (1)字节流:操作的数据是字节 ...
- Android(java)学习笔记214:开源框架的文件上传(只能使用Post)
1.文件上传给服务器,服务器端必然要写代码进行支持,如下: 我们新建一个FileUpload.jsp的动态网页,同时我们上传文件只能使用post方式(不可能将上传数据拼凑在url路径下),上传数据Ap ...
- maya和Unity中的坐标系旋转
maya软件是用的右手坐标系,默认旋转顺序是ZYX,即先绕Z轴旋转,再绕Y轴旋转,最后绕X轴旋转. 比如在maya软件中,右侧的旋转顺序是可选的,默认的选择是“XYZ”,其实物体旋转顺序是倒着念,即上 ...