亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

隱藏文本中的特定單詞而不添加新標簽

隱藏文本中的特定單詞而不添加新標簽

慕姐8265434 2023-08-05 21:01:18
我有這個代碼:<div>Lorem ispum custom test</div>我只會隱藏而不刪除“自定義”一詞,而不添加任何新標簽。我能怎么做?謝謝
查看完整描述

3 回答

?
月關寶盒

TA貢獻1772條經驗 獲得超5個贊

您可以使用蒙版或剪輯路徑。請注意,這不是一個可靠的解決方案,因為您需要根據字體屬性和真實文本調整值:


.box {

  /* the text to hide start at 90px and end at 137px */

  -webkit-mask:linear-gradient(to right,#fff 90px,transparent 0 137px,#fff 0)

}

<div class="box">Lorem ispum custom test</div>


使用剪輯路徑:


.box {

  /* the text to hide start at 90px and end at 137px */

  clip-path: polygon(0 0, 90px 0, 90px 100%, 137px 100%, 137px 0, 100% 0, 100% 100%, 0 100%);

}

<div class="box">Lorem ispum custom test</div>


查看完整回答
反對 回復 2023-08-05
?
忽然笑

TA貢獻1806條經驗 獲得超5個贊

不幸的是,你不能用 CSS 做到這一點,但你可以用 jQuery 替換這個詞,如下所示:


jQuery(document).ready( function($){

? $('div').each(function(){

? ? var txt = $('div').text();

? ? var res = txt.replace('custom', '');

? ? $('div').text(res);

? });

});

重要提示:請記住,這將遍歷您的所有 div,因為您的 div 沒有 class 或 id 屬性

查看完整回答
反對 回復 2023-08-05
?
瀟瀟雨雨

TA貢獻1833條經驗 獲得超4個贊

這就是您稍后可以使用您的數組的方式。


var strings = [];

var str = document.getElementById("par");

if (str.textContent.includes("one")){

  var now = str.textContent.replace("one ", "");

  str.textContent = now;

  strings.push("one ")

};

console.log(strings)

<p id="par">this one is changed</p>


查看完整回答
反對 回復 2023-08-05
  • 3 回答
  • 0 關注
  • 177 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號