我正在尝试制作一个待办事项列表应用程序,并尝试在添加到列表中的每个元素旁边添加一个可点击的复选框。我对此很陌生,所以非常感谢任何帮助!
谢谢!
function todoList() {
var item = document.getElementById('todoInput').value
var text = document.createTextNode(item)
var newItem = document.createElement("li")
newItem.appendChild(text)
document.getElementById("todoList").appendChild(newItem)
}
<form id="todoForm">
<h1>To Do List:<h1>
<input id="todoInput">
<button type="button" onclick="todoList()">Add Item</button>
</form>
<ul id="todoList">
</ul>
最佳答案
更新 Javascript
function todoList() {
var item = document.getElementById('todoInput').value
var text = document.createTextNode(item)
var newItem = document.createElement("li")
newItem.appendChild(text)
var checkbox = document.createElement('input');
checkbox.type = "checkbox";
checkbox.name = "name";
checkbox.value = "value";
checkbox.id = "id";
newItem.appendChild(checkbox);
document.getElementById("todoList").appendChild(newItem)
}
关于Javascript 待办事项列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42358758/