Javascript待办事项列表

时间:2017-02-21 04:35:13

标签: javascript html css checkbox

我正在尝试制作一个待办事项列表应用,并尝试在每个项目旁边添加一个可点击的复选框,因为它已添加到列表中。我对此非常陌生,所以非常感谢任何帮助!

谢谢!

   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>

 

2 个答案:

答案 0 :(得分:2)

更新Javscript

jsFiddle Demo

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)
    }  

答案 1 :(得分:0)

我相信你想要添加复选框,而不是子弹。以下代码就是这样做的。如果您想了解有关创建“Todo list”应用的更多信息,请从TodoMVC

中获取灵感

char *line = "Feb 21 20:15:58";
struct tm t;

strptime (line, "%B %d %T", &t);
printf ("%ld\n", mktime (&t));
1