【16】jQuery

來源:互聯網
上載者:User

標籤:

jQuery

模組:Dom和JavaScript

版本:1.12.x相容IE9以下的瀏覽器

2.x不相容IE9

一、尋找

1.選取器

  • #id選取器
  • 標籤選取器
  • 類型選取器
  • 組合選取器
  • 層級選取器

 

2.篩選器

樣本:多級菜單顯示隱藏

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Title</title>    <style>        .hide{            display: none;        }        .menu{            width: 200px;            height: 600px;            border: 1px solid #dddddd;            overflow: auto;        }        .menu .item .title{            height: 40px;            line-height: 40px;            background-color: #2459a2;            color: white;        }    </style></head><body>    <div class="menu">            <div class="item">                <div class="title" onclick="ShowMenu(this);">菜單一</div>                <div class="body">                    <p>內容一</p>                    <p>內容一</p>                    <p>內容一</p>                    <p>內容一</p>                    <p>內容一</p>                </div>            </div>            <div class="item">                <div class="title"  onclick="ShowMenu(this);">菜單二</div>                <div class="body hide">                    <p>內容二</p>                    <p>內容二</p>                    <p>內容二</p>                    <p>內容二</p>                    <p>內容二</p>                    <p>內容二</p>                </div>            </div>            <div class="item">                <div class="title"  onclick="ShowMenu(this);">菜單三</div>                <div class="body hide">                    <p>內容三</p>                    <p>內容三</p>                    <p>內容三</p>                    <p>內容三</p>                    <p>內容三</p>                    <p>內容三</p>                </div>            </div>        </div>    <script src="jquery-1.12.4.js"></script>    <script>        function ShowMenu(ths) {            // console.log(ths);  // Dom中的標籤對象            // $(ths)             // Dom標籤對象轉換成jQuery標籤對象(jQuery應用更便利)            // $(ths)[0]          // jQuery標籤對象轉換成Dom標籤對象            // 刪除本身內的hide隱藏            $(ths).next().removeClass(‘hide‘);            // 尋找父類的兄弟標籤內為body的樣式為body的標籤,增加hide樣式            $(ths).parent().siblings().find(‘.body‘).addClass(‘hide‘);        }    </script></body></html>

3.Dom標籤對象與jQuery標籤對象轉換

console.log(ths);        // Dom中的標籤對象$(ths)                   // Dom標籤對象轉換成jQuery標籤對象(jQuery應用更便利)$(ths)[0]                // jQuery標籤對象轉換成Dom標籤對象
二、操作

1.CSS操作

2.屬性操作

3.文本操作

樣本:jQery全選/取消/反選

 

樣本:clone實現搜尋條件+-

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Title</title></head><body>    <div>        <p>            <a onclick="Add(this);">+</a>            <input type="text" />        </p>    </div>    <script src="jquery-1.12.4.js"></script>    <script>        function Add(ths) {            var p = $(ths).parent().clone();            p.find(‘a‘).text(‘-‘);            p.find(‘a‘).attr(‘onclick‘, ‘Remove(this);‘);            $(ths).parent().parent().append(p);        }        function Remove(ths) {            $(ths).parent().remove();        }    </script></body></html>

  

 

三、事件

1.如何使用jQuery綁定

2.當文檔載入完畢後,自動執行

  $(function(){

  ......

  });

3.延遲綁定

四、擴充

1.自訂模組

2.Form表單驗證

 

五、jQuery迴圈

.each()

 

【16】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.