1、HTML识别文本空格回车换行展示
1)方式一:增加如下样式属性即可
<p style = 'white-space: pre-wrap;'>
第一段。
第二段。
第三段。
</p>
2)方式二:正则匹配替换
var oTxt = $('p').html();
//匹配换行符与回车符
$('p').html(oTxt.replace(/[\r\n]/g,'<br>'));
//匹配空格
$('p').html(oTxt.replace(/\s/g,' '));
1、HTML识别文本空格回车换行展示
1)方式一:增加如下样式属性即可
<p style = 'white-space: pre-wrap;'>
第一段。
第二段。
第三段。
</p>
2)方式二:正则匹配替换
var oTxt = $('p').html();
//匹配换行符与回车符
$('p').html(oTxt.replace(/[\r\n]/g,'<br>'));
//匹配空格
$('p').html(oTxt.replace(/\s/g,' '));