gpt4 book ai didi

javascript - 如何在html中呈现多行字符串变量

转载 作者:行者123 更新时间:2023-11-30 14:30:23 25 4
gpt4 key购买 nike

我需要在 Angular 4 View (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 文件中的变量使用数据绑定(bind)在 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>

关于javascript - 如何在html中呈现多行字符串变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51291433/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com