第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

根據(jù)特定文本刪除各種 div

根據(jù)特定文本刪除各種 div

有只小跳蛙 2022-08-04 16:53:00
我有這個(gè)DOM,我想像過濾器一樣根據(jù)h5標(biāo)簽中包含的文本刪除li。<div class="total">  <ul>   <li>    <h5>this super heroe is super cool: Clark Kent</h5>   </li>  </ul>  <ul>   <li>    <h5>I always wanted to be Batman</h5>   </li>  </ul>  <ul>   <li>    <h5>Somedays I will be transform as Spiderman </h5>   </li> </ul>  <ul>   <li>    <h5>This women is incredible Catwoman</h5>   </li>  </ul>   <li>    <ul>     <h5>The worst character is Joker</h5>   </ul>   </li>   <ul>    <li>     <h5>Someone knows about Green Lantern </h5>    </li>   </ul></div>我需要根據(jù)字符串將過濾器放入此數(shù)組中,該數(shù)組沒有昏迷let appDataTab = ["Clark Kent    Catwoman     Joker"]我的目標(biāo)是刪除所有李,它的h5不滿足“克拉克肯特”,“貓女”和“小丑”,因?yàn)槟憧梢钥吹絘ppDataTab內(nèi)容這些字符串沒有分離。
查看完整描述

2 回答

?
MMTTMM

TA貢獻(xiàn)1869條經(jīng)驗(yàn) 獲得超4個(gè)贊

以下是從我端驗(yàn)證后添加其他代碼后的更新代碼。


<!DOCTYPE html>

<html>

<head>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

</head>

<body>

    <div class="total">

        <ul>

            <li>

                <h5>this super heroe is super cool: Clark Kent</h5>

            </li>

        </ul>

        <ul>

            <li>

                <h5>I always wanted to be Batman</h5>

            </li>

        </ul>

        <ul>

            <li>

                <h5>Somedays I will be transform as Spiderman </h5>

            </li>

        </ul>

        <ul>

            <li>

                <h5>This women is incredible Catwoman</h5>

            </li>

        </ul>

        <ul>

            <li>

                <h5>The worst character is Joker</h5>

            </li>

        </ul>        

        <ul>

            <li>

                <h5>Someone knows about Green Lantern </h5>

            </li>

        </ul>

    </div>

    <script>

        $(function () {

            var prohibited = ['Clark Kent', 'Catwoman', 'Joker'];


            $("li").each(function (index) {

                var wordFound = false;


                for (var i = 0; i < prohibited.length; i++) {


                    if ($(this).text().indexOf(prohibited[i]) > -1) {

                        wordFound = true;

                        break;

                    }

                }


                if (wordFound == false) {

                    $(this).parent().remove();

                }

            });

        })

    </script>

</body>

</html>


查看完整回答
反對(duì) 回復(fù) 2022-08-04
?
飲歌長嘯

TA貢獻(xiàn)1951條經(jīng)驗(yàn) 獲得超3個(gè)贊

您應(yīng)該首先使其成為常規(guī)的逗號(hào)分隔數(shù)組,然后查找該元素并刪除包含該元素的數(shù)組。li


逐個(gè)注釋步驟:


$(document).ready(function () {

//Your array

var appDataTab = ["Clark Kent    Catwoman     Joker"];

//Split with more than 1 space (2 space)

var appDataSplit = appDataTab[0].split("  ");

//Remove empty elements

var filtered = appDataSplit.filter(function (el) {

  return el != "";

});

//Trim elements from extra spaces

var cleanFiltered = [];

for (i=0; i < filtered.length; i++){

  cleanFiltered.push(filtered[i].trim());

}

console.log(cleanFiltered);

//look for any li containing the words in cleanFilter array

  $("li").each(function(){

    for (i=0; i < cleanFiltered.length;i++){

      if ($(this).text().indexOf(cleanFiltered[i]) > -1) {

        $(this).remove();

      }  

    }

  });

});

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div class="total">

  <ul>

   <li>

    <h5>this super heroe is super cool: Clark Kent</h5>

   </li>

  </ul>


  <ul>

   <li>

    <h5>I always wanted to be Batman</h5>

   </li>

  </ul>


  <ul>

   <li>

    <h5>Somedays I will be transform as Spiderman </h5>

   </li>

 </ul>


  <ul>

   <li>

    <h5>This women is incredible Catwoman</h5>

   </li>

  </ul>


   <ul>

    <li>

     <h5>The worst character is Joker</h5>

   </li>

   </ul>


   <ul>

    <li>

     <h5>Someone knows about Green Lantern </h5>

    </li>

   </ul>

</div>


查看完整回答
反對(duì) 回復(fù) 2022-08-04
  • 2 回答
  • 0 關(guān)注
  • 134 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)