jQuery 使用手册(二)

2020-05-23 06:19:54易采站长站整理

}$(“#ch”).children()得到对象[<span>two</span><span id=”sp”>three</span> ].
$(“#ch”).children(“#sp”)过滤得到[<span id=”sp”>three</span> ]parent ()  parent (expr)取匹配对象父节点的。参照children帮助理解
contains(str)  返回匹配对象中包含字符串str的对象
<p>This is just a test.</p><p>So is this</p>jQuery代码及功能:
function jq(){
    alert($(“p”).contains(“test”).html());
}$(“p”)得到两个对象,而包含字符串”test”只有一个。所有$(“p”).contains(“test”)返回 [ <p>This is just a test.</p> ]end() 结束操作,返回到匹配元素清单上操作前的状态.

filter(expr)   filter(exprs)   过滤现实匹配符合表达式的对象 exprs为数组,注意添加“[ ]”
<p>Hello</p><p>Hello Again</p><p class=”selected”>And Again</p>jQuery代码及功能:
function jq(){
    alert($(“p”).filter(“.selected”).html())
}$(“p”)得到三个对象,$(“p”).contains(“test”)只返回class为selected的对象。
find(expr)  在匹配的对象中继续查找符合表达式的对象
<p>Hello</p><p id=”a”>Hello Again</p><p class=”selected”>And Again</p>Query代码及功能:
function jq(){
    alert($(“p”).find(“#a”).html())
}在$(“p”)对象中查找id为a的对象。
is(expr)  判断对象是否符合表达式,返回boolen值
<p>Hello</p><p id=”a”>Hello Again</p><p class=”selected”>And Again</p>Query代码及功能:
function jq(){
    alert($(“#a”).is(“p”));
}在$(“#a “)是否符合jquery表达式。
大家可以用$(“#a”).is(“div”);  (“#a”).is(“#a”)多来测试一下
next()  next(expr)  返回匹配对象剩余的兄弟节点
<p>Hello</p><p id=”a”>Hello Again</p><p class=”selected”>And Again</p>jQuery代码及功能
function jq(){
        alert($(“p”).next().html());
        alert($(“p”).next(“.selected”).html());
}$(“p”).next()返回 [ <p id=”a”>Hello Again</p> , <p class=”selected”>And Again</p> ]两个对象