只在文本中插入新行

编程入门 行业动态 更新时间:2024-10-11 01:11:43
本文介绍了只在文本中插入新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用CMS,它只允许特定div中的文本(HTML,比如< br> ,被解析为& amp ; LT峰; br&安培; GT; )。使用Unicode / HTML代码(例如& amp; )会生成& 和&#x00040; 会生成 @ ),但它看起来不允许换行/回车。我怎样才能在div中添加一个< br> 而不使用HTML?

我试过了:

  • & NewLine; - dev.w3/html5/html-author/charref
  • &#10; - 新line in text area
  • &#13; - 文本区域中的新行
  • &#x0a; 或& #xa; 或&#x0000a; - en.wikipedia/wiki/Newline
  • &#x0d; 或& #xd; 或&#x0000d; - en.wikipedia/wiki/Newline

这里有一个问题(和CMS输出的HTML结构相同)> jsfiddle/w3p4wgcc/ ...难道不可能?

解决方案

使用内联css我已经设法做到以下几点:

< div style =white-space:pre-wrap;> 这是一些新的文本,&#10;这个文本应该在一个新的行。 < / div>

jsfiddle/6mqgrym9/

如果你需要所有的div都像这样,你可以在你的样式表中说明以下内容:

div { white-space:pre-wrap; $ b

如果这些div包含在一个根div(它有一个id)一个可以做到以下几点:

#idhere> div { white-space:pre-wrap; $ b $ p $ b

如果你可以使用一些javascript,你可以试试这个: p>

< div> < script> document.currentScript.parentNode.innerHTML ='这是一些新的文本< br>这段文字应该放在新的一行。 < / script> < / div>

I'm working with a CMS that allows only text in a certain div (HTML , like <br>, is parsed to &lt;br&gt;). It is fine with Unicode / HTML codes (e.g. &amp; would generate & and &#x00040; would generate @) but it will seemingly not allow a new line / carriage return. How can I put a <br> in the div, without using HTML?

I've tried:

  • &NewLine; - dev.w3/html5/html-author/charref
  • &#10; - New line in text area
  • &#13; - New line in text area
  • &#x0a; or &#xa; or &#x0000a; - en.wikipedia/wiki/Newline
  • &#x0d; or &#xd; or &#x0000d; - en.wikipedia/wiki/Newline

Here is a fiddle with the same issue (and HTML structure as output by CMS) > jsfiddle/w3p4wgcc/ ...Is it just not possible?

解决方案

With inline css i've managed to do the following:

<div style="white-space: pre-wrap;"> This is some new text,&#10;this text should be on a new line. </div>

jsfiddle/6mqgrym9/

If you need all of your divs to be like this one could say in your stylesheet the following:

div { white-space: pre-wrap; }

if these divs are contained in a root div (which has a id) one could do the following:

#idhere > div { white-space: pre-wrap; }

If you're allowed to use some javascript you can try this:

<div> <script> document.currentScript.parentNode.innerHTML = 'This is some new text<br>this text should be on a new line.'; </script> </div>

更多推荐

只在文本中插入新行

本文发布于:2023-10-26 18:12:24,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:只在   文本中

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!