我一直试图在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事件上添加/删除该类.

Jquery相关问答推荐

我在自定义 WordPress 插件中使用 ajax 时收到错误请求

JQuery AJAX 成功事件未触发

修改对象数组中的对象属性

提醒未保存的表单更改

使用 JavaScript/jQuery 重定向到 ASP.NET MVC 中的另一个页面

未捕获的类型错误:$.post 不是函数

确定 JavaScript 值是否为整数?

如何重新启用 event.preventDefault?

使用 jquery/ajax 刷新/重新加载 Div 中的内容

未捕获的 TypeError:data.push 不是函数

jQuery:如何从 $.ajax.error 方法中获取 HTTP 状态代码?

消除移动 Safari 中点击事件的 300 毫秒延迟

在jquery中查找具有某个属性值的所有元素

所有但不是jQuery Select 器

订单对象是否由指定的 jQuery Select 器返回?

jquery 检测某些类的 div 已添加到 DOM

jquery更改div类的样式属性

将数据发布到 JsonP

一起使用 JQuery-Mobile/Phonegap 的正确方法?

如何禁用由子元素触发的 mouseout 事件?