遇到JS的换行和空格问题,我是这么解决的

JS换行可以添【< br />】,方式如下

<script>
document.write('hello <br/>world')
</script>

JS 添加空格可以采用如下两种方式:
插入【&nbsp】

<script>
document.write('hello &nbsp &nbsp world')
</script>

或者:
插入语句【"< span style=‘white-space:pre;’>"】和【’</ span>’】,注意前一句的双引号

<script>
document.write("<span style='white-space:pre;'>"+'h   ello  wor   ld'+'</span>')
</script>
发布了34 篇原创文章 · 获赞 4 · 访问量 2181

猜你喜欢

转载自blog.csdn.net/qq_41629800/article/details/105267296