2015-10-09 42 views
0

我有搜索結果,它們在句子的開頭連接了多個單詞。如何使用jQuery刪除div中的多個文本?

<div itemprop="articleSection" class="entry-summary"> 
WHAT WE DOSource Integrate Support Manage Transform A metre-wide 「lazy river」 of cobblestones meanders through the clay-paved plaza fronting Australia’s newest international-standard swim centre. 
</div> 

我想刪除的話從一開始就 「我們DOSource集成支持管理轉變」EACHclass="entry-summary"

謝謝!

回答

1

您可以使用此jQuery的

jQuery的

$('.entry-summary').each(function() { 
    var text = $(this).text(); 
    $(this).text(text.replace('WHAT WE DOSource Integrate Support Manage Transform', '')); 
}); 

DEMO HERE

+0

工程就像一個魅力。謝謝路易斯!你真棒 –

+0

好的回答路易斯。希望任何讀這個知道的人都知道要改變你的.removetext選擇器來匹配他們擁有的選擇器。在OP的情況下「.removetext」將更改爲「.entry-summary」 – kasdega

+0

@kasdega謝謝...我編輯我的答案基礎上的OP –

0

你可以只把它分解:

$('.entry-summary:contains("Transform ")').text(function(_, txt){ 
    return txt.split('Transform ')[1]; 
}); 
+0

謝謝你的回答 –

1

使用.text方法來改變文字:

$('.entry-summary').text(function(index, value) { 
    return value.replace(
    /^\s*WHAT WE DOSource Integrate Support Manage Transform/, 
    '' 
); 
}); 
+0

哇..謝謝 –

+0

這是我也會用的答案。 – kasdega

0

可以使用str_replace函數的功能。

var str = $(".entry-summary").html(); 
var res = str.replace("WHAT WE DOSource Integrate Support Manage Transform", ""); 
$(".entry-summary").html(res); 
+0

偉大的解決方案。謝謝你,先生 –

相關問題