Advertisement
Pavle_nis

Javascript lista

Nov 7th, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <title></title>
  6. </head>
  7. <body>
  8. <ul id="lista">
  9. <li>Ponedeljak</li>
  10. <li>Utorak</li>
  11. <li>Sreda</li>
  12. <li>Cetvrtak</li>
  13. <li>Petak</li>
  14. <li>Subota</li>
  15. <li>Nedelja</li>
  16. </ul>
  17. <input id="Text1" type="text" placeholder="Unesi tekst" />
  18. <br /><br />
  19. <input id="Text2" type="text" placeholder="Unesi broj"/>
  20. <br /><br />
  21. <input id="Button1" type="button" value="Dodaj" onclick="dodaj()" />
  22. <input id="Button2" type="button" value="Procitaj" onclick="procitaj()" />
  23. <input id="Button3" type="button" value="Obrisi" onclick="obrisi()" />
  24.  
  25. <p id="p1"></p>
  26.  
  27. <script src="js.js"></script>
  28. </body>
  29. </html>
  30.  
  31.  
  32. function dodaj()
  33. {
  34. text1 = document.getElementById("Text1");
  35. var lista = document.getElementById("lista");
  36. var li = document.createElement("li");
  37. li.appendChild(document.createTextNode(text1.value));
  38. lista.appendChild(li);
  39. }
  40.  
  41. function procitaj()
  42. {
  43. tekst = document.getElementById("p1");
  44. broj = document.getElementById("Text2");
  45. lista = document.getElementById("lista");
  46.  
  47. tekst.innerHTML = lista.getElementsByTagName("li")[broj.value].innerHTML;
  48. }
  49.  
  50. function obrisi()
  51. {
  52. broj = document.getElementById("Text2");
  53. lista = document.getElementById("lista");
  54.  
  55. lista.removeChild(lista.childNodes[broj.value]);
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement