Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在jquery中,可以将action绑定到一个尚不存在的元素上,如何在原生js中做到这一点?
$("body").on("input", ".element", function() { });
获取body标签并将事件附加到它使用addEventListener
body
addEventListener
document.getElementsByTagName('body')[0].addEventListener('input', function(e) { if (e.target.id === 'element') { console.log(e.target.value) } })
<input class='element' id='element'>