我想使用 jquery/javascript 将以下 html 代码转换为连续的字符串。
<ul>
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
这是当我使用 $('#description').text()
阅读这些内容时放置在 textarea 中的 html(id 为“描述”) ,我得到这个描述为
one
two
three
相反,我想把它写成“一二三”,即连续的,有什么建议吗?
最佳答案
您需要删除换行符。
someText = $('#description').text();
someText = someText.replace(/(\r\n|\n|\r)/gm,"");
或者用空格代替:
someText = someText.replace(/(\r\n|\n|\r)/gm," ");
--
http://www.textfixer.com/tutorials/javascript-line-breaks.php
关于javascript - 如何将无序列表(UL,LI)转换为连续字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8726211/