# jQuery 常用 API
# 1. 介绍
jQuery 常用 API
# 2. 选择器
# 2.1. *
说明:
- Selects all elements.
# 2.2. :animated
说明:
- 正在执行 jQuery 动画(如
slideToggle
)的元素
# 2.3. [name|="value"]
说明:
- 匹配 name 属性,且值为 value 或 value-
示例:
<a hreflang="en">匹配</a>
<a hreflang="en-UK">匹配</a>
<a hreflang="english">不匹配</a>
<script>
$( "a[hreflang|='en']" ).css( "border", "3px dotted green" );
</script>
# 2.4. 参考
# 3. 样式
# 3.1. .addClass()
说明:
- Adds the specified class(es) to each element in the set of matched elements.
语法:
// One or more space-separated classes to be added to the class attribute of each matched element.
.addClass( string ): JQuery<TElement>
// An array of classes to be added to the class attribute of each matched element. version added: 3.3
.addClass( string[] ): JQuery<TElement>
// A function returning one or more space-separated class names to be added to the existing class name(s). Receives the index position of the element in the set and the existing class name(s) as arguments. Within the function, this refers to the current element in the set.
.addClass( (this: TElement, index: number, currentClassName: string) => string | string[] ): JQuery<TElement>
# 3.2. .removeClass()
说明:
- Remove a single class, multiple classes, or all classes from each element in the set of matched elements.
语法:
// One or more space-separated classes to be removed from the class attribute of each matched element.
.removeClass( string ): JQuery<TElement>
// An array of classes to be removed from the class attribute of each matched element. version added: 3.3
.removeClass( string[] ): JQuery<TElement>
// A function returning one or more space-separated class names or an array of class names to be removed. Receives the index position of the element in the set and the old class value as arguments.
.removeClass( (this: TElement, index: number, className: string) => string | string[] ): JQuery<TElement>
# 3.3. .hasClass()
说明:
- Determine whether any of the matched elements are assigned the given class.
语法:
.hasClass(className: string): boolean
# 3.4. .toggleClass()
说明:
- Add or remove one or more classes from each element in the set of matched elements, depending on either the class's presence or the value of the state argument.
语法:
.hasClass(className: string): boolean
# 3.5. .css()
# 3.6. .width()
# 3.7. .height()
# 3.8. .innerHeight()
# 3.9. .innerWidth()
# 3.10. .offset()
说明:
- 获取/设置 文档位置,相对文档
示例:
$('.box').offset();
//=> { left: 100, top: 200 }
$('.box').offset({ left: 100, top: 200 });
# 3.11. .position()
说明:
- 获取相对父元素的位置
示例:
$('.box').position();
//=> { left: 100, top: 200 }
# 3.12. .outerHeight()
# 3.13. .outerWidth()
# 3.14. .scrollLeft()
# 3.15. .scrollTop()
# 3.16. jQuery.cssHooks
# 3.17. jQuery.cssNumber
# 3.18. jQuery.escapeSelector()
# 4. 参考
上一篇: 下一篇:
本章目录