Ashley’s Blog

A blogging framework for Ashley.

JQuery API

JQuery API

jQuery( “prev + next” )

同一个父元素下紧接在 “prev” 元素后的 “next” 元素

jQuery( “prev ~ siblings” )

匹配 “prev” 元素之后的所有 兄弟元素。具有相同的父元素,并匹配过滤“siblings”选择器。

jQuery( “:eq(index)” )

注意 因为 :eq() 是一个 jQuery 延伸出来的选择器,并不是的CSS规范的一部分, 使用:eq()查询不能充分利用原生DOM提供的querySelectorAll() 方法来提高性能。为了在现代浏览器上获得更佳的性能,请使用$(“your-pure-css-selector”).eq(index)代替。

jQuery( “:has(selector)” )

如果表达式 $(‘div:has(p)’) 匹配一个<div>,那么应有一个<p>存在于<div>后代元素中的任何地方,不是直接的子元素也可以。它匹配的是 <div> 而不是 <p>, 对比 $(“div p”)

jQuery( “[attribute|=‘value’]” )

选择指定属性值等于给定字符串或以该字符串为前缀(该字符串后跟一个连字符“-” )的元素。

jQuery( “[attribute~=‘value’]” )

选择指定属性用空格分隔的值中包含一个给定值的元素。

jQuery( “:nth-child(index/even/odd/equation)” )

选择他们所有父元素的第n个子元素。 用:nth-child(n)时 ,所有子元素都计算在内,不管它们是什么,并且指定的元素被选中仅匹配连接到伪类选择器。而用:eq(n)时,只有与这个伪类前面的选择相匹配的元素才会被计数(即,成为候选元素),不限于任何其他元素的孩子,而且第(n +1)个一(n是基于0)被选中。

.height()

返回的是数值, 只是纯粹的 height 数值,与此相对应的是 css(‘height’) 返回带 px 的字符串,innerHeight() 返回height+padding的数值

.outerHeight( [includeMargin ] )

height+padding+border or height+padding+border+margin

.offset() and .position()

.offset()是获得该元素相对于documet的当前坐标,而.position()方法可以取得元素相对于父元素的偏移位置

选择器

基本 * .class element #id selector1, selectorN, … 层级 parent > child ancestor descendant prev + next prev ~ siblings 基本筛选 :animated :eq() :even :first :gt() :header :lang() :last :lt() :not() :odd :root :target 内容筛选 :contains() :empty :has() :parent

可见性筛选 :hidden :visible 属性 [name|=“value”] [name*=“value”] [name~=“value”] [name$=“value”] [name=“value”] [name!=“value” [name^=“value”] [name] [name=“value”][name2=“value2”] 子元素筛选 :first-child :first-of-type :last-child :last-of-type :nth-child() :nth-last-child() :nth-last-of-type() :nth-of-type() :only-child :only-of-type()

表单 :button :checkbox :checked :disabled :enabled :focus :file :image :input :password :radio :reset :selected :submit :text 属性 / CSS

属性 .attr() .prop() .removeAttr() .removeProp() .val() CSS .addClass() .css() jQuery.cssHooks .hasClass() .removeClass() .toggleClass() 尺寸 .height() .innerHeight() .innerWidth() .outerHeight() .outerWidth() .width() 位置 .offset() .offsetParent() .position() .scrollLeft() .scrollTop() 数据 jQuery.data() .data() jQuery.hasData() jQuery.removeData() .removeData() 操作

拷贝 .clone() DOM 插入, 包裹 .wrap() .wrapAll() .wrapInner() DOM 插入, 内部插入 .append() .appendTo() .html() .prepend() .prependTo() .text() DOM 插入, 外部插入 .after() .before() .insertAfter() .insertBefore() DOM 移除 .detach() .empty() .remove() .unwrap() DOM 替换 .replaceAll() .replaceWith() 遍历

筛选 .eq() .filter() .first() .has() .is() .last() .map() .not() .slice() 各种遍历 .add() .andSelf() .contents() .each() .end() 树遍历 .addBack() .children() .closest() .find() .next() .nextAll() .nextUntil() .parent() .parents() .parentsUntil() .prev() .prevAll() .prevUntil() .siblings()

重大更新!这么写实在太慢了 还是直接贴网址比较好 JQUery API