【www.gdgbn.com--jquery】

1.$。在jquery 中$(""),这个语法等同于$(document.createelement("span")) ,这是一种用法,在选择元素的时候还会这样子的用:[attribute$=value],匹配给定的属性是以某些值结尾的元素。下面举个例子来说明一下:
html代码



jquery 代码:
$("input[name$="letter"]")
结果:
[ , ]
2.!。选择器:[attribute!=value],匹配所有不含有指定的属性,或者属性不等于特定值的元素,此选择器等价于:not([attr=value])。
例子说明一下:
html代码



jquery 代码:
$("input[name!="newsletter"]").attr("checked", true);
结果:
[ ]
3.*。选择器:[attribute*=value],匹配给定的属性是以包含某些值的元素。举个例子说明一下:
html 代码:




jquery 代码:
$("input[name*="man"]")
结果:
[ , , ]
4.@。匹配包含给定属性的元素。注意,在jquery 1.3中,前导的@符号已经被废除!如果想要兼容最新版本,只需要简单去掉@符号即
可。
5.^。选择器:[attribute^=value],匹配给定的属性是以某些值开始的元素,下面举个例子来说明一下:
html 代码:



jquery 代码:
$("input[name^="news"]")
结果:
[ , ]

在jquery中,当使用$("input[name="metaid"]“).val()不能直接获得被选择的radio的值,只是获得 radio标签的第一个值,这可能jquery使用xpath语言了进行查找有关,而我们通常是想获得被选中的radio的值,有以下几种方法:
1,使用$("input[name="metaid"]:checked").val()获得 //name代表radio中name属性名
2,使用$(":radio:checked").val()获得 //限制页面只有一组radio标签


语法总结和注意事项
1、关于页面元素的引用通过jquery的$()引用元素包括通过id、class、元素名以及元素的层级关系及dom或者xpath条件等方法,且返回的对象为jquery对象(集合对象),不能直接调用dom定义的方法。
2、jquery对象与dom对象的转换只有jquery对象才能使用jquery定义的方法。注意dom对象和jquery对象是有区别的,调用方法时要注意操作的是dom对象还是jquery对象。普通的dom对象一般可以通过$()转换成jquery对象。如:$(document.getelementbyid("msg"))则为jquery对象,可以使用jquery的方法。由于jquery对象本身是一个集合。所以如果jquery对象要转换为dom对象则必须取出其中的某一项,一般可通过索引取出。如:$("#msg")[0],$("div").eq(1)[0],$("div").get()[1],$("td")[5]这些都是dom对象,可以使用dom中的方法,但不能再使用jquery的方法。以下几种写法都是正确的:$("#msg").html();$("#msg")[0].innerhtml;$("#msg").eq(0)[0].innerhtml;$("#msg").get(0).innerhtml;


29.children(expr)取得子节点,当expr为空时,取得所有的子节点

eg: hello

hello again

and again

$("div").children() ==>> [hello

hello again

and again

]

$("div").children(".selected") ==>> [

hello again

]
children纯选择功能.当无参数是是选择所有子元素.当有条件时,按条件所选.例二是选择class为selected的节点!

30.add(params) 在$所取到的节点数组中添加新的节点.

参数可以是expr, html,element

eg: 1.

hello

hello again

$("p").add("span") ==>> [

hello

, hello again ]

eg: 2.

hello

$("p").add("again") ==> [

hello

, again ]

eg: 3.

hello

hello again

$("p").add(document.getelementbyid("a") ) ==>> [

hello

, hello again ]
增加元素或是html内容.增加到搜索的元素之后.例三,是提取id为a的子元素到p元素之后,这时子元素的地位改变,与p元素并列

 

31.contains(str)找出字节点中包含有str的节点,str起到过滤做用

eg:

this is just a test.

so is this

$("p").contains("test") ==>> [

this is just a test.

]

contains也纯选择功能.参数是str类型.即选择test中包括有test内容的节点

32.filter(expression)过滤找出符合expression的节点

eg:

hello

hello again

and again

$("p").filter(".selected") ==>>

and again

$("p").filter(".selected, :first") ==>> [

hello

,

and again

]
属于多条件查询.selected应该是class为selected的节点.:first应该是第一个节点!

 

filter(filter_func)通过函数来选择是否过滤,filter_func返回true表示过滤

    hello

how are you?

$("p").filter(function(index) { return $("ol", this).length == 0; })==>[

how are you?

]
filter 还可以以函数为条件!

33.find(expr)从子节点找出符合expr的.与filter的区别是filter过滤掉$数组中的节点find过滤到的是子节点

eg:

hello, how are you?

$("p").find("span") ==>> [ hello ]
与filter相反,感觉都差不多

34.is(expr) 判断是否符合条件,如果$数组的所有节点都不符合条件返回false,只要有一个符合条件就返回true

eg:

$("input[@type="checkbox"]").parent().is("form") ==>> false

$("input[@type="checkbox"]").parent().is("p") ==>> true
条件判断!

35.next(expr) 取得最近节点那个节点.expr为空时取得所有节点

eg:1.

hello

hello again

and again

$("p").next() ==>> [

hello again

, and again ]

eg:2.

hello

hello again

and again

$("p").next(".selected") ==>>[

hello again

]
感觉没什么特别的.

36. not(el),not(expr),not(elems)与add相反,删除符合条件的节点.

eg:1.

hello

hello again

$("p").not($("#selected")[0]) ==>> [

hello

]

$("p").not("#selected") ==>> [

hello

]

eg:2.

hello

hello again

$("p").not($("div p.selected")) ==>> [

hello

]
删除条件中的节点,反回删除后的结果

37 parent(expr) 取得父节点

eg:1.

hello

hello again

$("span").parents() ==>> [ ..., ...,

hello

]
参数为空时取得所有父节点

eg:2.

hello

hello again

$("span").parents("p") ==>>[

hello

]
有条件时取得第一个父节点.

38.prev(expr) 与next相反,next取得是与节点相邻后面的.prev取得相邻前面的

eg:1.hello

hello again

and again

$("p").prev(".selected") ==>> [ hello ]

eg:2.

hello

hello again

and again

$("p").prev() ==>> [ hello again ]
这个很明显,取得条件之前的节点.next没那么明显,

39.siblings(expr) 取得相邻两边的节点是.next,与prev的结合体
这两个把next和prev整合了

本文来源:http://www.gdgbn.com/wangyezhizuo/29738/