Add event to button with javascript

后端 未结 4 1270
忘掉有多难
忘掉有多难 2020-12-18 23:24

In this page there\'s a way to dynamic add html (textbox,input button and radio elements with javascript

my questioon is how can i add an event to the button, imagi

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-18 23:55

    You have to attach the new event when creating the DOM element.

    For example :

    var e = document.createElement('input');
    e.onclick = function()
                {
                   alert('Test');
                };
    

提交回复
热议问题