鋒利的jquery學習筆記

來源:互聯網
上載者:User

標籤:des   style   blog   http   color   os   ar   strong   art   

1.$("#tt")擷取的永遠都是一個jquery對象,所以要判斷頁面上是否存在某個對象不能像js中

if($("#tt")){}
View Code

而是通過:

if($("#tt").length > 0){}
View Code

ps:當頁面中不存在id為tt的元素時,jQuery不會報錯,而js中會報錯

2. jQuery層選取器$("ancestor descendant")和$("parent>child")

<div>This is <strong>very</strong> important.</div><div>This is <em>really <strong>very</strong></em> important.</div>
View Code

好比一家人三代同堂,爺爺,父親和你,這樣話爺爺的子項目就是你父親,同時你父親也是爺爺的後代元素,而你只是爺爺的後代元素。

總結:後代元素包括子項目,子項目是指父親的第一代。

3. jQuery選取器的種類

  3.1 基本選取器

  3.2 層次選取器

  3.3 過濾選取器

    3.3.1 基本過濾選取器

        $("div:first") 選擇第一個div;$("div:last")選擇最後一個div;$("input:not(.myclass)")選擇類不是myclass的input;$("input:even")選擇索引為偶數的

                     input ;$("input:odd")選擇索引為奇數的input;$("input:eq(1)")選擇索引等於1的input元素;$("input:gt(1)")選擇索引大於1input;$("input:lt(1)"

                     選擇索引小於1的input

  3.4 表單選取器

  

鋒利的jquery學習筆記

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.