我需要去掉字符串的某些元素。
字符串看起来有点像这样:
var htmlelement = '<b>Frame</b>: KHAKI TORT / MATTE BLACK<br>
<b>Lens</b>: <span class="titlecaps">SMOKE MONO</span><br>
<b>Protection</b>: Category 3 lens - Maximum UV protection
<div><b>Hardware</b>: Initial temple badge<br>
<b>Packaging</b>: Le Specs protective pouch included<br>
<b>Gender</b>: Men
<div><b>Model</b>: 1202055<br>
<b>Warranty</b>: Le Specs are warranted for one year against manufacturing faults from the date of purchase.<br>
<br>
<hr style="border:dotted #DDD; border-width:1px 0 0 0; height:0;line-height:0px;font-size:0;margin:0;padding:10px;">
<span style="font-family:times new roman;"><span style="font-weight:bold">DESIGNER NOTES</span><br>
<br>
This oversize and tough wayfarer style in khaki tortoiseshell features a contrast black top bar.
</span>
</div>
</div>'
因为我已经从 HTML 元素转换它们。
我需要去掉的是镜头和框架,所以对于上面的字符串,我需要返回这个:
Frame: KHAKI TORT / MATTE BLACK
Lens: SMOKE MONO
为了解决问题,字符串可能并不总是与呈现的完全相同,例如初始字符串可能如下所示(以不同的顺序):
<b>Model</b>: 1202080<br>
<b>Protection</b>: Category 3 lens - Maximum UV protection
<div><b>Hardware</b><span>:</span><b> </b><span>Silver logo temple badge</span><br>
<b>Packaging</b>: Le Specs protective pouch included<br>
<b>Gender</b>: Women<br>
<b>Warranty</b>: Le Specs are warranted for one year against manufacturing faults from the date of purchase.<br>
<br>
<b>Frame</b>: <span style="titlecaps">BLACK PRINT</span><br>
<hr style="border:dotted #DDD; border-width:1px 0 0 0; height:0;line-height:0px;font-size:0;margin:0;padding:10px;">
<b>Lens</b>: <span class="titlecaps">SMOKE GRAD</span><br>
<span style="font-family:times new roman;"><span style="font-weight:bold">DESIGNER NOTES</span><br>
<br>
Bold and glamorous, this oversize square style features soft curves featuring signature Le Specs Aztec print.
</span>
</div>
我仍然需要简单地返回这个:
Frame: BLACK PRINT
Lens: SMOKE GRAD