我有从文本文件中读取并插入元素的脚本,以便可以对它们进行样式化和显示。但是,我现在想要在DIV内部配对两个元素。这里是代码:在DIV中配对数组元素
var lines = request.responseText.replace(/\r/g, "").split("\n"); // Remove carriage returns (\r) and place text into an array, split at the newline character (\n)
for (var i = 0; i < lines.length; i++) { // Cycle through each line in the array
if (lines[i].length >= 57) { // Check if the current line is lengthy, and if so.....separate function
}
var coup = document.createElement("div"); // Create a div element
coup.id = "line" + i; // Give the div an ID in the form of line0, line1, etc.
coup.innerText = coup.textContent = lines[i]; // Place the current line of text in the div
el_status.appendChild(coup); // Append the div to the status box
}
我想line0和line1进入一个DIV。然后,我想第2行和第3行进入另一个DIV ...
var coup不一定是一个div,我不介意将它改为p,span或li。
谢谢!
顺便说一句,'//创建一个div元素'等明显的注释会适得其反。 –