每次将项目添加到数组时都会运行此函数。它只是创建一个列表项元素,将一些文本 append 到该项目,然后将其 append 到一个列表元素 (#requestList)。
function UpdateListOnScreen(NewListItem){
var grabList = document.getElementById('requestList');
var text = ""+ GetCalendarName(NewListItem.calChoice) +" For "+ GetLessonSlot(NewListItem.lessonChoice) + " On " + GetDateInTextForm(NewListItem.date) + "";
var entry = document.createElement('li');
entry.id = list.length-1;
entry.className = "ItemNotChecked";
entry.appendChild(document.createTextNode(text));
grabList.appendChild(entry);
}
我正在努力弄清楚如何将按钮元素添加到该列表项上?我希望每个列表项都有自己的按钮元素,但似乎无法弄清楚在将文本 append 到列表项之后如何将按钮 append 到列表项。
谢谢。
最佳答案
这是一个如何插入按钮的示例:
var ul = document.getElementById("list");
var li = document.createElement("li");
li.appendChild(document.createTextNode("Four"));
var button = document.createElement("button");
button.innerHTML = "asdasd";
li.appendChild(button);
li.setAttribute("id","element4");
ul.appendChild(li);
alert(li.id);
<ul id="list"></ul>
关于javascript - 如何使用 JavaScript 将按钮 append 到列表项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28830982/