Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想从页面上的元素中获取文本。我不想要 html 标签,但我想要换行符。如果我这样做$('#element').text(),则删除换行符。没有html标签的元素中保留段落的方法是什么?
$('#element').text()
一个快速而肮脏的解决方案是提取 HTML,用某些字符串替换所有和标签<p>,然后使用 jQuery 将 HTML 转换为文本,然后用 s 替换这些特定字符串。</p><br>.text\n
<p>
</p>
<br>
.text
\n
这远非完美的解决方案,但对于您的情况可能就足够了。