现在的位置: 首页 > 综合 > 正文

JQuery学习笔记(一)

2013年01月17日 ⁄ 综合 ⁄ 共 3948字 ⁄ 字号 评论关闭
一、jQuery基础
1、jQuery包装器——选择器
2、jQuery实用功能——$静态函数
3、Document ready 句柄
4、生成Dom元素
5、扩展jQuery
6、结合jQuery和其他类库

二、选择器
1、选择元素并进行包装

可以使用CSS选择器来选择元素,完全的CSS3标准兼容

Selector Description
* Matches any element.
E Matches all element with tag name E.
E F Matches all elements with tag name F that are descendents of E.
E>F Matches all elements with tag name F that are direct children of E.
E+F Matches all elements F immediately preceded by sibling E.匹配与E节点为直接兄弟节点的F节点(向下搜索)
E~F Matches all elements F preceded by any sibling E.匹配任何与E为兄弟节点的F节点(向下搜索)
E:has(F) Matches all elements with tag name E that have at least one descendent with tag name F.
E.C Matches all elements E with class name C. Omitting E is the same as *.C.
E#I Matches element E with id of I. Omitting E is the same as *#I.
E[A] Matches all elements E with attribute A of any value.
E[A=V] Matches all elements E with attribute A whose value is exactly V.
E[A^=V] Matches all elements E with attribute A whose value begins with V.
E[A$=V] Matches all elements E with attribute A whose value ends with V.
E[A*=V] Matches all elements E with attribute A whose value contains V.

:first The first match of the page.
:last The last match of the page.
:first-child The first child element.
:last-child The last child element.
:only-child Returns all elements that have no siblings.
:nth-child(n) The nth child element. 以1为基
:nth-child(even|odd) Even or odd children.
:nth-child(Xn+Y) The nth child element computed by the supplied formula.
:even and :odd Even and odd matching elements page-wide.
:eq(n) The nth matching element.以0为基
:gt(n) Matching elements after (and excluding) the nth matching element.以0为基
:lt(n) Matching elements before (and excluding) the nth matching element.以0为基

:animated Selects elements that are currently under animated control.
:button Selects any button (input[type=submit], input[type=reset],input[type=button], or button).
:checkbox Selects only check box elements (input[type=checkbox]).
:checked Selects only check boxes or radio buttons that are checked (supported by CSS).
:contains(foo) Selects only elements containing the text foo.
:disabled Selects only form elements that are disabled in the interface (supported by CSS).
:enabled Selects only form elements that are enabled in the interface (supported by CSS).
:file Selects all file elements (input[type=file]).
:header Selects only elements that are headers; for example: <h1> through<h6> elements.
:hidden Selects only elements that are hidden.
:image Selects form images (input[type=image]).
:input Selects only form elements (input, select, textarea, button).
:not(filter) Negates the specified filter.
:parent Selects only elements that have children (including text), but not empty elements.
:password Selects only password elements (input[type=password]).
:radio Selects only radio elements (input[type=radio]).
:reset Selects reset buttons (input[type=reset] or button[type=reset]).

:selected Selects option elements that are selected.
:submit Selects submit buttons (button[type=submit] orinput[type=submit]).
:text Selects only text elements (input[type=text]).
:visible Selects only elements that are visible.

2、在DOM中创建HTML元素

如果想要创建空的DOM元素,可以使用$("<div>")

3、操作包装元素集(methods)

size()    包装集中元素的个数
get(index)    得到指定索引的html元素;如果不输入任何参数,则返回整个数组
index(ele)    返回指定元素在包装集中的索引
add(exp|ele)    向包装集中添加元素
not(exp)
filter(sel|func)    移除所有返回false的元素,this代表当前元素
slice(begin,end)    返回begin与end之间的包装集子集

children() Returns a wrapped set consisting of all unique children of the wrapped elements. 直接的子节点
contents() Returns a wrapped set of the contents of the elements, which may include text nodes, in
the wrapped set. (Frequently used to obtain the contents of <iframe> elements.)
next() Returns a wrapped set consisting of all unique next siblings of the wrapped elements.
nextAll() Returns a wrapped set containing all the following siblings of the wrapped elements.
parent() Returns a wrapped set consisting of the unique direct parents of all wrapped elements.
parents() Returns a wrapped set consisting of the unique ancestors of all wrapped elements. This
includes the direct parents as well as the remaining ancestors all the way up to, but not
including, the document root.
prev() Returns a wrapped set consisting of all unique previous siblings of the wrapped elements.
prevAll() Returns a wrapped set containing all the previous siblings of the wrapped elements.
siblings() Returns a wrapped set consisting of all unique siblings of the wrapped elements

find(selector) or $(selector, wrappedSet)
is(selector)
.end()
.andSelf()    合并之前的包装集

抱歉!评论已关闭.