简体   繁体   中英

Add oninput attribute to HTML element with Javascript

How do I add oninput to an html <input> element with javascript?

newinput.oninput = 'foo();';

This does not work - is there a way to do this?

 document.getElementById('my_input').addEventListener("input", function () { console.log('input happened;'); });
 <input id="my_input">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM