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

jquery 节点操作.删除和取值

2013-07-27 11:48 204 查看
1.add(params) 在$所取到的节点数组中添加新的节点.参数可以是expr, html,elementeg: 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.getElementByIdx_x("a") ) ==>> [
Hello

, Hello Again ]增加元素或是html内容.增加到搜索的元素之后.例三,是提取id为a的子元素到p元素之后,这时子元素的地位改变,与p元素并列2.children(expr)取得子节点,当expr为空时,取得所有的子节点eg:
Hello
Hello Again
And Again

$("div").children() ==>> [Hello
Hello Again
And Again

]$("div").children(".selected") ==>> [
Hello Again
]children纯选择功能.当无参数是是选择所有子元素.当有条件时,按条件所选.例二是选择class为selected的节点!3.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内容的节点4.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应该是第一个节点!5.filter(filter_func)通过函数来选择是否过滤,filter_func返回true表示过滤

Hello

How are you?

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

]filter 还可以以函数为条件!6.find(expr)从子节点找出符合expr的.与filter的区别是filter过滤掉$数组中的节点find过滤到的是子节点eg:
Hello, how are you?

$("p").find("span") ==>> [ Hello ]与filter相反,感觉都差不多7.is(expr) 判断是否符合条件,如果$数组的所有节点都不符合条件返回false,只要有一个符合条件就返回trueeg:

$("input[@type='checkbox']").parent().is("form") ==>> false$("input[@type='checkbox']").parent().is("p") ==>> true条件判断!8.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
]感觉没什么特别的.9. 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

]删除条件中的节点,反回删除后的结果10.parent(expr) 取得父节点eg:1.

Hello

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

]参数为空时取得所有父节点eg:2.

Hello

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

]有条件时取得第一个父节点.11.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没那么明显,
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: