1. <!DOCTYPE html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
    6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    7. <title>Document</title>
    8. <style>
    9. </style>
    10. </head>
    11. <body>
    12. <input type="text" id="inp">
    13. <div class="box"></div>
    14. <script>
    15. var inp = document.querySelector('#inp')
    16. var box = document.querySelector(".box")
    17. var arr = []
    18. inp.addEventListener('keyup', function (e) {
    19. if (e.keyCode == 13) {
    20. var value = this.value
    21. if (!arr.includes(value)) {
    22. arr.push(value)
    23. var p = document.createElement('p')
    24. var txt = document.createTextNode(value);
    25. p.appendChild(txt)
    26. box.appendChild(p)
    27. for (let i = 0; i < box.children.length; i++) {
    28. box.children[i].onclick = function () {
    29. // console.log(this);
    30. box.removeChild(this);
    31. }
    32. }
    33. }
    34. // .appendChild(p)
    35. }
    36. })
    37. </script>
    38. </body>
    39. </html>