[英]I've tried every line break for createTextNode but I can't make one
/n
doesn't work on my code as it doesn't print out a line break. /n
在我的代码上不起作用,因为它不会打印出换行符。 Please help! 请帮忙!
</br>
doesn't work </br>
不起作用
<script>
var x = document.createElement("TABLE");
x.setAttribute("id", "myTable");
document.body.appendChild(x);
var y = document.createElement("TR");
y.setAttribute("id", "myTr");
document.getElementById("myTable").appendChild(y);
var z = document.createElement("TD");
var column = 1
for(row = 1; row < 13; row++){
var product = column*row;
if(column != 13){
var t = document.createTextNode(product + " ")
if(row == 12){
column += 1
var t = document.createTextNode(product + " \u000a" + column)
row = 1;
}
}
else if(column == 13){
break
}
z.appendChild(t);
document.getElementById("myTr").appendChild(z);
}
</script>
This is what I get: 这是我得到的:
1 2 3 4 5 6 7 8 9 10 11 12 24 6 8 10 12 14 16 18 20 22 24 36 9 12 15 18 21 24 27 30 33 36 48 12 16 20 24 28 32 36 40 44 48 510 15 20 25 30 35 40 45 50 55 60 612 18 24 30 36 42 48 54 60 66 72 714 21 28 35 42 49 56 63 70 77 84 816 24 32 40 48 56 64 72 80 88 96 918 27 36 45 54 63 72 81 90 99 108 1020 30 40 50 60 70 80 90 100 110 120 1122 33 44 55 66 77 88 99 110 121 132 1224 36 48 60 72 84 96 108 120 132 144 13 1 2 3 4 5 6 7 8 9 10 11 12 24 6 8 10 12 14 16 18 20 22 24 36 9 12 15 18 21 24 27 30 33 36 48 12 16 20 24 28 32 36 40 44 48 510 15 20 25 30 35 40 45 50 55 60 612 18 24 30 36 42 48 54 60 66 72 714 21 28 35 42 49 56 63 70 77 84 816 24 32 40 48 56 64 72 80 88 96 918 27 36 45 54 63 72 81 90 99 108 1020 30 40 50 60 70 80 90 100 110120 1122 33 44 55 66 77 88 99 110121 132 1224 36 48 60 72 84 96 108 120 132 144 13
The problem is you are making a table with a single table row. 问题是您要制作一个带有单个表行的表。 If you want it to be in multiple rows, you need multiple
tr
. 如果希望它位于多行中,则需要多个
tr
。
This is what you currently have. 这就是您目前拥有的。
<table id="myTable">
<tr id="myTr">1\n 2\n 3\n</tr>
</table>
This is what you seem to want. 这就是您似乎想要的。
<table id="myTable">
<tr id="myTr">1 2 3 4</tr>
<tr>3 4 5 6</tr>
</table>
You can try the studying the following code as an example 您可以尝试研究以下代码作为示例
This will create a table with the numbers 1 - 50 with 5 rows and 10 columns. 这将创建一个数字表1-50,具有5行和10列。
I do not recommend using \\t
for separation or visual type of stuff. 我不建议将
\\t
用于分隔或视觉化的东西。 You should consider using CSS for styling spacing and whatnot. 您应该考虑使用CSS设置间距样式以及诸如此类。
var table = document.createElement("table"); table.setAttribute("id", "myTable"); const ROWS = 5; const COLUMNS = 10; var product = 1; for (var i = 0; i < ROWS; i++) { // Create the rows element var row = document.createElement("tr"); for (var j = 0; j < COLUMNS; j++) { // Put the "product" in the row. \\t is the tab seperator, for easy view. row.appendChild(document.createTextNode(product+"\\t")); product += 1; } // Append the row with the data in the table. table.appendChild(row); } // Append the table to the body element to view. document.body.appendChild(table);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.