【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给我做了封装,是获取元素统一了标准 ...
随机推荐
- 开发Mhealth(即:Mobile Health 移动医疗)应用必知的10个掘金点
近 日,著名移动技术咨询公司Research2Guidance发布了最新版的<移动医疗应用开发者经济>报告.在过去的两年半里,iOS和Android 两大主流移动平台上的移动医疗应用(以下 ...
- PHP: 深入pack/unpack <转> [链接]
PHP: 深入pack/unpack PHP: chr和pack.unpack那些 PHP: pack/unpack补遗
- 2015 UESTC Winter Training #10【Northeastern Europe 2009】
2015 UESTC Winter Training #10 Northeastern Europe 2009 最近集训都不在状态啊,嘛,上午一直在练车,比赛时也是刚吃过午饭,状态不好也难免,下次比赛 ...
- 【开源java游戏框架libgdx专题】-02-Eclipse Gradle 环境安装
创建eclipse开发环境 Eclipse 4.5 Help -> install newsoftware 填上下载地址(Eclipse 4.5及以上版本): http://dist.sprin ...
- 使用jq深入研究轮播图特性
网站轮播图 太耳熟的词了 基本上做pc端的 主页绝壁会来一个轮播图的特效 轮播图他一个页面页面的切换,其实的原理是通过css的定位 ,定位到一起,第一张首先显示,其余默认隐藏. 今天我实现的这个轮播 ...
- 织梦DeDeCms列表分页和内容页分页错位解决办法
文章页分页代码在这里/include/arc.archives.class.php列表页分页/include/arc.listview.class.php 很多入门的站长会碰到这样的问题,织梦的通病, ...
- application/json IE 兼容问题
由于IE系列浏览器把application/json响应视为文件,并尝试下载在网上看了一下,大致了解,只要修改返回的内容的类型(ContentType)即可解决问题. 由于ajax请求,返回类型默认就 ...
- XML参数转换为Object,并转换为List或DataTable
demo效果:
- 运行phpize时出现:Cannot find autoconf. Please check your autoconf installation
运行/usr/local/webserver/php/bin/phpize时出现:Configuring for:PHP Api Version: 20041225Zend Module Api No ...
- iOS面试小题集锦
1.Object-C有多继承吗?没有的话用什么代替? cocoa 中所有的类都是NSObject 的子类 多继承在这里是用protocol 委托代理 来实现的你不用去考虑繁琐的多继承 ,虚基类的概 ...