Advertisement
GreMendes

TODO

Oct 22nd, 2015
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. <!DOCTYPE html>
  4. <html>
  5.  
  6. <head>
  7.   <meta charset="utf-8"/>
  8.   <title>Lista de tarefas</title>
  9. </head>
  10.  
  11. <body>
  12.  
  13. <h1>Lista de tarefas</h1>
  14.  
  15. <form id="tarefaForm">
  16.   <input type="text" name="tarefa" id="descricao"/>
  17.   <button type="submit">Enviar</button>
  18. </form>
  19.  
  20. <button value="Limpar" id="limpa">Limpar tarefas</button>
  21.  
  22. <ul id="tarefas">
  23. </ul>
  24.  
  25.  
  26. <script type="text/javascript" source src="todo.js"></script>
  27.  
  28. </script>
  29.  
  30. </body>
  31.  
  32. </html>
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42. todo.js
  43.  
  44. (function () {
  45.     "use strict";
  46.  
  47.     function Tarefa(descricao) {
  48.         this.descricao = descricao;
  49.     }
  50.  
  51.     var tarefas = [];
  52.  
  53.     document.getElementById("tarefaForm").onsubmit = function(e) {
  54.         e.preventDefault();
  55.         var descricao = document.getElementById("descricao").value;
  56.         tarefas.push(new Tarefa(descricao));
  57.         atualizarTarefa();
  58.         document.getElementById("descricao").value = "";
  59.     }
  60.  
  61.     function atualizarTarefa(){
  62.     var i = 1;
  63.         var lista = document.getElementById("tarefas");
  64.         lista.innerHTML = "";
  65.  
  66.         tarefas.forEach(function(tarefa){
  67.  
  68.       var ckbox = document.createElement("input");
  69.       ckbox.setAttribute("type", "checkbox");
  70.       ckbox.setAttribute("name", "ck");
  71.       ckbox.setAttribute("value", "ck");
  72.       ckbox.setAttribute("id", "i");
  73.  
  74.       var check = document.create
  75.             var item = document.createElement("li");
  76.             item.innerHTML = tarefa.descricao;
  77.       lista.appendChild(ckbox);
  78.             lista.appendChild(item);
  79.  
  80.       document.getElementById("i").addEventListener("click", function(){
  81.         alert("Hello World!");
  82.       });
  83.  
  84.  
  85.         });
  86.     }
  87.  
  88.  
  89.  
  90.  
  91. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement