標題:
[java/VB script]
JQuery的DOM操作
[打印本頁]
作者:
gswdkimo
時間:
2011-10-26 10:50
標題:
JQuery的DOM操作
1. children() 返回選擇器對象的子節點
<p>one</p>
<div id="ch">
<span>two</span>
</div>
jQuery代碼及功能:
function jq(){
alert($("#ch").children().html());
}
$("#ch").children()得到元素[
<span>two</span>
].
所以html()的結果是 [
two
]
2. children(expr) 返回選擇器對象的子節點中符合表達式的節點
<div id="ch">
<span>two</span>
<span id="sp">three</span>
</div>
jQuery代碼及功能
function jq(){
alert($("#ch").children("#sp").html());
}
$("#ch").children()得到元素 [
<span>two</span><span id="sp">three</span>
].
$("#ch").children("#sp")過濾得到元素 [
<span id="sp">three</span>
]
另外還可以用
E[@attr=value] 屬性的值完全相同的要素E $("h3[@class=hdr]")
E[@attr^=value] 屬性的值以value開頭的要素E $("a[@href^=http://blog.xuite.net]")
E[@attr$=value] 屬性的值以value結尾的要素E $("a[@href$=.pdf]")
E[@attr*=value] 屬性的值含有value的要素E $("a[@href*=xuite.net]")
來取得想要的元素.
歡迎光臨 資訊家電班NO7 (http://imce07.freehostia.com/forums/)
Powered by Discuz! 7.2