從某標籤A內的B標籤,即從A標籤中選擇B標籤($("#B")是擷取整個頁面中的B標籤),即擷取A標籤的子標籤B,怎麼擷取?

來源:互聯網
上載者:User

從某標籤A內的B標籤,即從A標籤中選擇B標籤($("#B")是擷取整個頁面中的B標籤),即擷取A標籤的子標籤B。


<div id="a">

<ul class="XXX YYY am-list-striped">

</ul>

<div id="a1">

<div id="a11">

<input id="test" value="hello" />

</div>

</div>

<div id="a2"></div>

</div>

<div id="b"></div>

<div id="c"></div>

從id為“test”的標籤的父標籤的父標籤中,找到其class為:

1)錯誤的,方式。

$($("#test").parent().parent().parent(),"ul[class$='am-list-striped']")。//這種是錯誤的,

alert($($("#test").parent().parent().parent(),"ul[class$='am-list-striped']").html());//結果如下


這種方式,擷取的明顯是$("#test").parent().parent().parent(),這一句並沒有起作用"ul[class$='am-list-striped']"。

這種文法就是錯的,所以不能使用這種方式。真正使用jQuery的選取器的兩個參數來實現父標籤取子標籤,如下文法才是正確的:


2)正確的方式

$($("#test").parent().parent().parent(),"ul[class$='am-list-striped']");//正確的方式



所以,

所以遇到從父標籤中取子標籤的,就用find函數。

http://www.jb51.net/article/21660.htm

https://zhidao.baidu.com/question/571272157.html




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.