[英]Need to remove text between html tags
我有一些 HTML 格式的內容,我想刪除標簽之間的評論示例。
例如:內容就像
<p dir="ltr" id="_13" style="margin-left: 0px; "><span style="font-size: 11pt; font-family: times new roman,times; ">Time span values shall allow creation or retrieval using any of the following units:<br><br> Days<br><br> Hours<br><br> Minutes<br><br> Seconds<br><br> Milliseconds<br><br> Microseconds</span><br><br><span style="font-size: 12pt; font-family: times new roman,times; "><b><i>Comments</i></b></span><span style="font-size: 12pt; font-family: times new roman,times; "><i> Example</i></span></p>
我想專門刪除評論示例。 我可以在兩個單獨的變量中獲取它,但基本上它們連續出現的地方只有它應該被刪除。
預期結果將是:
<p dir="ltr" id="_13" style="margin-left: 0px; "><span style="font-size: 11pt; font-family: times new roman,times; ">Time span values shall allow creation or retrieval using any of the following units:<br><br> Days<br><br> Hours<br><br> Minutes<br><br> Seconds<br><br> Milliseconds<br><br> Microseconds</span><br><br><span style="font-size: 12pt; font-family: times new roman,times; "><b><i></i></b></span><span style="font-size: 12pt; font-family: times new roman,times; "><i></i></span></p>
提前致謝!!
您可以使用span:eq()
選擇元素,然后只使用text()
:
$('#_13').find('span:eq(1) i').text(''); $('#_13').find('span:eq(2) i').text('');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <p dir="ltr" id="_13"> <span style="font-size: 11pt; font-family: times new roman,times;"> Time span values shall allow creation or retrieval using any of the following units:<br><br> Days<br><br> Hours<br><br> Minutes<br><br> Seconds<br><br> Milliseconds<br><br> Microseconds </span><br><br> <span style="font-size: 12pt; font-family: times new roman,times;"><b><i>Comments</i></b></span> <span style="font-size: 12pt; font-family: times new roman,times; "><i>Example</i></span> </p>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.