添加“新行”在innerHTML中 [英] Add a "new line" in innerHTML
本文介绍了添加“新行”在innerHTML中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在第一个单元格中创建一个包含图像的表格,并在第二个单元格中创建有关图片的信息。
I am trying to create a table with images in first cell and information about the pic in second cell.
我需要在一个单元格中添加不同的信息,例如那:
I need to add different information in one cell, like that:
cellTwo.innerHTML = arr_title[element] + arr_tags[element];
是否可以在那里添加新行?
我的意思是:
Is it possible to add a "new line" there? I mean like that:
cellTwo.innerHTML = arr_title[element] + "/n" + arr_tags[element];
推荐答案
最简单的方法是将换行符添加为html
The simplest way is by adding a line break as html
cellTwo.innerHTML = arr_title[element] + "<br />" + arr_tags[element];
如果您希望按字面意思处理换行符,可以使用< ; pre>
tag
If you want your newlines to be treated literally, you could use the <pre>
tag
cellTwo.innerHTML =
"<pre>" + arr_title[element] + "\n" + arr_tags[element] + "</pre>";
这篇关于添加“新行”在innerHTML中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文