Is it possible to append to innerHTML without destroying descendants' event listeners?

前端 未结 13 1200
悲哀的现实
悲哀的现实 2020-11-21 23:40

In the following example code, I attach an onclick event handler to the span containing the text \"foo\". The handler is an anonymous function that pops up an <

13条回答
  •  一个人的身影
    2020-11-22 00:22

    The easiest way is to use an array and push elements into it and then insert the array subsequent values into the array dynamically. Here is my code:

    var namesArray = [];
    
    function myclick(){
        var readhere = prompt ("Insert value");
        namesArray.push(readhere);
        document.getElementById('demo').innerHTML= namesArray;
    }
    

提交回复
热议问题