我如何模拟纯JavaScript,CSS”激活mouseover:悬停”吗?

Zach SaucierDon Rhummy提出了一个问题:How do I simulate a mouseover in pure JavaScript that activates the CSS “:hover”?,或许与您遇到的问题类似。

回答者BoltClockBenjamin Gruenbaum给出了该问题的处理方式:

You can't. It's not a trusted event.

Events that are generated by the user agent, either as a result of user interaction, or as a direct result of changes to the DOM, are trusted by the user agent with privileges that are not afforded to events generated by script through the DocumentEvent.createEvent("Event") method, modified using the Event.initEvent() method, or dispatched via the EventTarget.dispatchEvent() method. The isTrusted attribute of trusted events has a value of true, while untrusted events have a isTrusted attribute value of false.

Most untrusted events should not trigger default actions, with the exception of click or DOMActivate events.

You have to add a class and add/remove that on the mouseover/mouseout events manually.

希望本文对你有帮助,欢迎支持JavaScript中文网

原文链接:stackoverflow.com

上一篇:如何在一页上添加两个谷歌图表?
下一篇:“u003c意味着什么?

相关推荐

官方社区

扫码加入 JavaScript 社区