午夜国产狂喷潮在线观看|国产AⅤ精品一区二区久久|中文字幕AV中文字幕|国产看片高清在线

    jquery中filter方法用法實(shí)例分析
    來(lái)源:易賢網(wǎng) 閱讀:988 次 日期:2015-02-10 14:18:43
    溫馨提示:易賢網(wǎng)小編為您整理了“jquery中filter方法用法實(shí)例分析”,方便廣大網(wǎng)友查閱!

    這篇文章主要介紹了jquery中filter方法用法,實(shí)例分析了filter方法的功能并對(duì)比了與find方法的區(qū)別,需要的朋友可以參考下

    本文實(shí)例講述了jquery中filter方法用法。分享給大家供大家參考。具體分析如下:

    filter()方法將匹配元素集合縮減為匹配指定選擇器的元素。

    filter方法中的參數(shù)可以為字符串值,包含供匹配當(dāng)前元素集合的選擇器表達(dá)式。

    一、filter的參數(shù)類型可分為兩種

    1、傳遞選擇器

    $('a').filter('.external')

    2、傳遞過(guò)濾函數(shù)

    代碼如下:

    $('a').filter(function(index) {

    return $(this).hasClass('external');

    })

    二、Jquery中find與filter區(qū)別

    1、find()會(huì)在div元素內(nèi) 尋找 class為classname的元素。

    2、filter()則是篩選div的class為classname的元素。

    3、基本是find子元素找,filter是平級(jí)找

    4、find 函數(shù)是在當(dāng)前對(duì)象集合的子元素中進(jìn)行查詢;

    5、filter 函數(shù)是對(duì)當(dāng)前對(duì)象集合進(jìn)行過(guò)濾, 利用過(guò)濾條件縮小范圍;

    6、find 函數(shù)的參數(shù)是 jQuery 選擇器表達(dá)式;

    7、filter 的參數(shù)也是選擇器表達(dá)式, 但可以有多個(gè)條件, 用逗號(hào)分隔(邏輯或關(guān)系);

    8、filter 的參數(shù)也可以是個(gè)函數(shù), 調(diào)用函數(shù)時(shí)會(huì)自動(dòng)傳入 index 參數(shù), 函數(shù)需返回 true或false 以選中或排除元素.

    例如:

    代碼如下:

    <!DOCTYPE>

    <html>

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">

    <title>Document</title>

    <script>

    $(function(){

    $('#btn1').click(function(){

    alert($('div').find('.test').html());

    });

    $('#btn2').click(function(){

    alert($('div').filter('.test').html());

    });

    $('#btn3').click(function(){

    alert($('div').filter('.last').html());

    });

    $('#btn4').click(function(){

    alert($('div').filter('.first,.last').html());

    });

    });

    </script>

    </head>

    <body>

    <input type="button" value="test-find" id="btn1" />

    <input type="button" value="test-filter" id="btn2" />

    <input type="button" value="test-filter" id="btn3" />

    <input type="button" value="test-filter" id="btn4" />

    <div class="first">first content<span class="test">test content</span></div>

    <div class="last">last<span class="test">last test content</span></div>

    <div class="last">last<span>last no test content</span></div>

    </body>

    </html>

    希望本文所述對(duì)大家的jQuery程序設(shè)計(jì)有所幫助。

    更多信息請(qǐng)查看IT技術(shù)專欄

    更多信息請(qǐng)查看腳本欄目
    易賢網(wǎng)手機(jī)網(wǎng)站地址:jquery中filter方法用法實(shí)例分析
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

    2025國(guó)考·省考課程試聽(tīng)報(bào)名

    • 報(bào)班類型
    • 姓名
    • 手機(jī)號(hào)
    • 驗(yàn)證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
    工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報(bào)警專用圖標(biāo)