[英]Need to remove text between html tags
I have some content in HTML format and i want to remove Comments Example between the tags.我有一些 HTML 格式的内容,我想删除标签之间的评论示例。
For eg: Content is like例如:内容就像
<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>
I want to specifically remove Comments Example.我想专门删除评论示例。 I can fetch it in two separate variables, but basically where they are present consecutively there only it should be removed.
我可以在两个单独的变量中获取它,但基本上它们连续出现的地方只有它应该被删除。
Expected result will be:预期结果将是:
<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>
Thanks in advance!!提前致谢!!
You can select the element using span:eq()
, and then just use text()
:您可以使用
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.