我有從文本文件中讀取並插入元素的腳本,以便可以對它們進行樣式化和顯示。但是,我現在想要在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元素'等明顯的註釋會適得其反。 –