您的位置:首页 > Web前端 > JQuery

JQuery学习笔记(1)

2013-08-11 17:48 225 查看
1.jQUERY对象有智能感知,Dom对象没有。区分Dom对象和jQuery对象是非常重要的。
2.Jquery对象是一个集合,可以通过索引来访问。并由此互相转化
3、使用它的遍历方法each(function(){alert(this)}).this是Dom元素
4.若要修改Dom元素的内容。可以这样用:$("#textDiv").each(function(){$(this).html("修改内容")}
5、jquery是核心对象。$是对jquery对象的引用。其语法为:
jQuery( selector, context )
Return: jQuery 包装集
根据选择器选取匹配的对象, 以jQuery包装集的形式返回. context可以是Dom对象集合或jQuery包装集, 传入则表示要从context中选择匹配的对象, 不传入则表示范围为文档对象(即页面全部对象).
6、selector选择器就是“一个表示特殊语意的字符串”。jQuery的选择器支持CSS3选择器的标准。
7、jQuery选择器按照功能主要分为“选择”和“过滤”。并且是配合使用的。
8、基础选择器:
(1)、jQuery( "element" )
element: An element to search for. Refers to the tagName of DOM nodes.
(2)、jQuery( "#id" )
id: An ID to search for, specified via the id attribute of an element.
(3)、jQuery( ".class" )
Description: Selects all elements with the given class.
class: A class to search for. An element can have multiple classes; only one of them must match.
(4)、jQuery( "*" )
Description: Selects all elements.
(5)、multiple selector
Description: Selects the combined results of all the specified selectors.
jQuery( "selector1, selector2, selectorN" )
selector1: Any valid selector.
selector2: Another valid selector.
selectorN: As many more valid selectors as you like.
注:会同时选中这几个选择器匹配的内容.是“或”的关系。要切记!
9、层次选择器:
(1)、Description: Selects all elements that are descendants of a given ancestor.
jQuery( "ancestor descendant" )
ancestor: Any valid selector.
descendant: A selector to filter the descendant elements.
A descendant of an element could be a child, grandchild, great-grandchild, and so on, of that element.(可以写多个连续父子关系的selector)
(2)、Child Selector (“parent > child”)
Description: Selects all direct child elements specified by "child" of elements specified by "parent".
jQuery( "parent > child" )
parent: Any valid selector.
child: A selector to filter the child elements.
The child combinator (E > F) can be thought of as a more specific form of the descendant combinator (E F) in that it selects only first-level descendants.
某选择器所指某父标签包含中的第一代孩子标签。不含孩子的孩子。要注意。
(3)、next adjacent selector
Description: Selects all next elements matching "next" that are immediately preceded by a sibling "prev".
jQuery( "prev + next" )
prev: Any valid selector.
next: A selector to match the element that is next to the first selector.
注意:One important point to consider with both the next adjacent sibling selector (prev + next) and the general sibling selector (prev ~ siblings) is that the elements on either side of the combinator must share the same parent.
(4)、Next Siblings Selector (“prev ~ siblings”)
Description: Selects all sibling elements that follow after the "prev" element, have the same parent, and match the filtering "siblings" selector.
jQuery( "prev ~ siblings" )
prev: Any valid selector.
siblings: A selector to filter elements that are the following siblings of the first selector.
注意:(3)、(4)必须两者都位于同一父亲下。The notable difference between (prev + next) and (prev ~ siblings) is their respective reach. While the former reaches only to the immediately following sibling element, the latter extends that reach to all following sibling elements.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: