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.
有没有办法调度所有元素?
例如,我们可以这样做window.dispatchEvent(evt),但我想允许所有元素使用该事件。(对于onclick,我们几乎可以使用所有元素)
window.dispatchEvent(evt)
var evt = document.createEvent("MouseEvents"); evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); [].forEach.call( document.getElementsByTagName("*"), function(elem){ elem.dispatchEvent(evt); });