繁体   English   中英

如何在html中显示多行字符串变量

[英]How to present a multi-line string variable in html

我需要在我的Angle 4视图(HTML)中显示多行变量。 问题是我将HTML标记br /放置在希望字符串断开并从新行开始的位置, 但是br /却显示为文本 我已经尝试过br /,\\ r br /,...这些作品都没有。 这是文本示例:

文件内容

<br /> xxxxx connects buyers of automotive parts and services with providers of those services. This document outline what information we collect from both the buyers and providers and how we handle this information, our privacy policy.<br />1. Scope of this Privacy Policy:<br /> xxxxxx and its parents, subsidiaries, representatives, affiliates, officers and directors (collectively, 'PuppyDog') values the privacy of individuals who use our application, websites, and related services. This privacy policy (the 'Privacy Policy') explains how we collect, use, and share information from xxxxxxx users (('Users'), comprised of both buyers of automotive parts and services and providers of those services.<br />2. Information We Collect-<br />Personal Information-<br />Buyers Registration Information. When you register as a.......

我应该指出,JSON文件中的变量使用数据绑定在HTML中显示值。 如有任何建议,我将不胜感激。

使用元素的innerHTML属性在其中添加HTML

 <script> var x = "<br /> xxxxx connects buyers of automotive parts and services with providers of those services. This document outline what information we collect from both the buyers and providers and how we handle this information, our privacy policy.<br />1. Scope of this Privacy Policy:<br /> xxxxxx and its parents, subsidiaries, representatives, affiliates, officers and directors (collectively, 'PuppyDog') values the privacy of individuals who use our application, websites, and related services. This privacy policy (the 'Privacy Policy') explains how we collect, use, and share information from xxxxxxx users (('Users'), comprised of both buyers of automotive parts and services and providers of those services.<br />2. Information We Collect-<br />Personal Information-<br />Buyers Registration Information. When you register as a......."; function addText(){ document.getElementById("x").innerHTML = x; } </script> <span id="x"></span> <br/> <button onClick="addText()">Fill span with text</button> 

使用以下语法: <div [innerHTML]="HTMLstring"></div>

要使用多行变量,请使用符号`

要使用新字符串,请使用\\n

像这样:

 var text=`\\n xxxxx connects buyers of automotive parts and services with providers of those services. This document outline what information we collect from both the buyers and providers and how we handle this information, our privacy policy.\\n 1. Scope of this Privacy Policy:\\n xxxxxx and its parents, subsidiaries, representatives, affiliates, officers and directors (collectively, 'PuppyDog') values the privacy of individuals who use our application, websites, and related services. This privacy policy (the 'Privacy Policy') explains how we collect, use, and share information from xxxxxxx users (('Users'), comprised of both buyers of automotive parts and services and providers of those services.\\n 2. Information We Collect-\\n Personal Information-\\n Buyers Registration Information. When you register as a....... `; alert(text); 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM