How to use addEventListener

≡放荡痞女 提交于 2019-11-29 06:54:49

Change the event listener like this

input.addEventListener("click", function(){
    createEntry(document.getElementById('a').value);
});

as it stands, you're passing the result of createEntry as an event listener, not the function itself

More information here:

https://developer.mozilla.org/en/docs/DOM/element.addEventListener

Change this line

input.addEventListener("click", createEntry(document.getElementById('a').value));

into

input.addEventListener("click", function(){
createEntry(document.getElementById('a').value);
});

Try using a JavaScript library like jQuery for event handling and DOM manipulation, to be browser safe and for uniformity.

You can use the event handlers in jQuery like the following:

$(<element_selector>).on("click", function (event) {
     // your code here...
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!