web篇---jQuery

來源:互聯網
上載者:User

標籤:this   more   nbsp   菜單   變數   prototype   css   1.4   str   

一.jQuery是什麼

<1> jQuery由美國人John Resig建立,至今已吸引了來自世界各地的眾多 javascript高手加入其team。

<2>jQuery是繼prototype之後又一個優秀的Javascript架構。其宗旨是——WRITE LESS,DO MORE!

<3>它是輕量級的js庫(壓縮後只有21k) ,這是其它的js庫所不及的,它相容CSS3,還相容各種瀏覽器

<4>jQuery是一個快速的,簡潔的javaScript庫,使使用者能更方便地處理HTMLdocuments、events、實現動畫效果,並且方便地為網站提供AJAX互動。

<5>jQuery還有一個比較大的優勢是,它的文檔說明很全,而且各種應用也說得很詳細,同時還有許多成熟的外掛程式可供選擇。

 

 

 

二.什麼是jQuery對象?

   jQuery 對象就是通過jQuery封裝DOM對象後產生的對象。jQuery 對象是 jQuery 專屬的. 如果一個對象是 jQuery 對象, 那麼它就可以使用 jQuery 裡的方法: $(“#test”).html();

 

$("#test").html()           //意思是指:擷取ID為test的元素內的html代碼。其中html()是jQuery裡的方法        // 這段代碼等同於用DOM實現代碼: document.getElementById(" test ").innerHTML;        //雖然jQuery對象是封裝DOM對象後產生的,但是jQuery無法使用DOM對象的任何方法,同理DOM對象也不能使用jQuery裡的方法.亂使用會報錯       //約定:如果擷取的是 jQuery 對象, 那麼要在變數前面加上$. var $variable = jQuery 對象var variable = DOM 對象$variable[0]:jquery對象轉為dom對象      $("#msg").html(); $("#msg")[0].innerHTML

 

jquery的基礎文法:$(selector).action()

 

 

 

三 .尋找元素(選取器和篩選器)

3.1選取器

3.1.1基本選取器

$("*")   $("#id")   $(".class")   $("element")   $(".class,p,div")

 

3.1.2層次選取器

$(".outer div")   $(".outer>div")   $(".oute+div")   $(".outer~div")

 

3.1.3基本選取器

$("li:first")   $("li:eq(2)")   $("li:even")   $("li:gt(1)")

 

3.1.4屬性選取器

$("[id=‘div1‘]")   $("[‘alex‘=‘sb‘][id]")

 

3.1.5表單選取器

$("[type=‘text‘]")------->$(":text")    注意適用於input標籤: $("input:checked")

 

 

執行個體之左側菜單(注意:jquery版本 的引用)

 

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>left_menu</title>    <script>          function show(self){              $(self).next().removeClass("hide");              $(self).parent().siblings().children(".con").addClass("hide");          }    </script>    <style>          .menu{              height: 500px;              width: 30%;              background-color: gainsboro;              float: left;          }          .content{              height: 500px;              width: 70%;              background-color: rebeccapurple;              float: left;          }         .title{             line-height: 50px;             background-color: #425a66;             color: forestgreen;}         .hide{             display: none;         }    </style></head><body><script src="jquery-3.2.1.js"></script><div class="outer">    <div class="menu">        <div class="item">            <div class="title" onclick="show(this);">菜單一</div>            <div class="con">                <div>111</div>                <div>111</div>                <div>111</div>            </div>        </div>        <div class="item">            <div class="title" onclick="show(this);">菜單二</div>            <div class="con hide">                <div>111</div>                <div>111</div>                <div>111</div>            </div>        </div>        <div class="item">            <div class="title" onclick="show(this);">菜單三</div>            <div class="con hide">                <div>111</div>                <div>111</div>                <div>111</div>            </div>        </div>    </div>    <div class="content"></div></div></body></html>

 

 

 

 

 

 

 

3.2 篩選器

3.2.1 過濾篩選器

 

3.2.2 尋找篩選器

 

web篇---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.