簡體   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