简体   繁体   English

如何获取这些HTML标签以从javascript呈现

[英]How do I get these HTML tags to render from javascript

Noob question alert! 新手问题提示! So, I've got this script, which loops through an array and adds a <br> tag to the end of each array item. 所以,我有这个脚本,它遍历一个数组并在每个数组项的末尾添加一个<br>标记。 But i dont know the proper way of displaying this output on my page. 但是我不知道在我的页面上显示此输出的正确方法。 Currently, when it loads the <br> tags show up on screen, whereas I want them to render as line-breaks. 目前,当它加载<br>标签时,它会显示在屏幕上,而我希望它们呈现为换行符。 It is outputting into a <textarea> if that makes a difference. 如果有区别,它将输出到<textarea> Thanks a bunch. 谢谢你

var outputLinkText = document.getElementById('outputLinkText');
var outputStageOne = "";

for (var i = 0; i < arrayOne.length; i++) {
    outputStageOne += (arrayOne[i] + "<br>");
}   

if ( 'textContent' in timePlace ) {
    outputLinkText.textContent = outputStageOne;
}
else {
    outputLinkText.innerText = outputStageOne;
}

<textarea> tags don't support <br> tags (or any other HTML tags) within their contents. <textarea>标记在其内容内不支持<br>标记(或任何其他HTML标记)。 They only hold plain text. 它们仅包含纯文本。

You need to add "\\n" as the separator instead. 您需要添加"\\n"作为分隔符。

(Strictly, it should be "\\r\\n" but a "\\n" on its own is usually sufficient) (严格来说,它应该是"\\r\\n"但是通常只要一个"\\n"就足够了)

Yes the textarea is a difference, try this : 是的,textarea有所不同,请尝试以下操作:

"\\r\\n" instead of "<br>" "\\r\\n"而不是"<br>"

暂无
暂无

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

相关问题 如何在Javascript文本节点内获取HTML标签? - How do I get HTML tags inside of a Javascript Text Node? 如何在javascript中呈现html文件? - How do I render an html file in javascript? 如何在不影响使用 Nodejs 或 Javascript 的 HTML 标签的情况下从 HTML 中获取 100 到 200 个单词? - How can I get 100 to 200 words from HTML without affecting HTML tags using Nodejs or Javascript? 如何使用 Javascript 在选定文本中获取所有 HTML 选择标签? - How do I get all the HTML selection tags in selected text using Javascript? 如何将此 javascript 和 HTML 代码添加到 angular 项目中? 我可以在 ZD18B8624A0F5F721DA7B82365FC56 中从 javascript function 渲染 html - How Do I add this javascript and HTML code into an angular project? and can i render html from javascript function in angular? 如何从ngModel呈现HTML标签? - How to render HTML Tags from ngModel? 如何在Javascript中生成多个新的HTML标签 - How do I generate multiple new HTML tags in Javascript 如何在例外的javascript中删除所有html标签? - How do I strip all html tags in javascript with exceptions? Javascript:如何扩展基于html标签的用户选择? - Javascript: How do I expand a user selection based on html tags? 在 JavaScript 中使用 fetch() 时,如何将返回的 object 中的详细信息渲染到 html 页面上 - When using fetch() in JavaScript how do I render details from the returned object onto the html page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM