我一直试图在Chrome中找到模拟mouseover
的代码,但即使"mouseover"侦听器被触发,CSS"hover"声明也从未设置过!
我还试着做:
//Called within mouseover listener
theElement.classList.add("hover");
但似乎没有什么东西能改变元素在其hover
声明中声明的内容.
这可能吗?
我一直试图在Chrome中找到模拟mouseover
的代码,但即使"mouseover"侦听器被触发,CSS"hover"声明也从未设置过!
我还试着做:
//Called within mouseover listener
theElement.classList.add("hover");
但似乎没有什么东西能改变元素在其hover
声明中声明的内容.
这可能吗?
你不能.这不是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.
您必须手动添加一个类,并在MouseOver/MouseOut事件上添加/删除该类.