更新时间:1970-01-01 07:55:30
您发布的代码实际上并未删除<br>
标记,只是在结果中看不到它们.我会用换行符替换那些以及换行符之后或文本开头的任何-",然后如上所述替换.
Your posted code doesn't actually remove the <br>
tags, you just don't see them in the results. I'd replace those, and any "-" after a newline or at the beginning of the text, with newlines, then replace as above.
$('.entry-content ul').each(function() {
var $this = $(this);
$this.html(
$this
.html()
.trim()
.replace(/^-|[\r\n]+-|<br>/g, "\n")
.replace(/[^\r\n]+/g, '<li>$&</li>')
);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class=entry-content>
<ul>
-1+ years of experience in End User Support<br>
-Experience re-imaging laptops<br>
-Great customer service experience
</ul>
</div>