javascript - 触发 CSS :active selector for non-anchor elements

标签 javascript jquery css

如何通过 JavaScript (jQuery) 触发非 anchor 元素的 :active 状态?


在审查时 Section 5.11.3 of the W3C CSS2 specification在引用 :hover pseudo selector to see about triggering a activation 时,我遇到了以下内容,这让我相信它应该是可能的:

"The :active pseudo-class applies while an element is being activated by the user. For example, between the times the user presses the mouse button and releases it."

"CSS does not define which elements may be in the above states, or how the states are entered and left. Scripting may change whether elements react to user events or not, and different devices and UAs may have different ways of pointing to, or activating elements."

感谢您的协助!

最佳答案

你不能用 javascript 触发像 :active 这样的 css 伪选择器。 没有可以执行的函数/处理程序,因此即使您在具有 css :active 伪选择器的元素上触发 单击设置(例如将背景颜色设置为红色),什么都不会发生。

关于javascript - 触发 CSS :active selector for non-anchor elements,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2990687/

相关文章:

javascript - 如何在Javascript中按类和id添加和删除类

javascript - 如果我想使用 jquery-ui 1.12.0 将两个图标添加到一个按钮怎么办

javascript - 禁用双重提交以防止发送提交名称

html - 将样式应用于 div 但不应用于 <strong> 子元素

javascript - jQuery 对话框函数

javascript - Visual Studio 2015 Javascript 概述方式太多

html - 使用 Bootstrap 实现响应式但填充更少的设计

javascript - 使用同一插件的多个实例

javascript - Canvas (HTML) 似乎正在缩放,而我想要具有更多像素的更大 Canvas

javascript - jQuery Listview 更改列表项颜色