我希望能够告诉一个元素它不再是 :active
以便 CSS 规则不再适用。有没有办法在 JavaScript 中做到这一点?
最佳答案
可能的解决方案:
1) 使用类:
JS:
document.getElementById("element").classList.remove("hasactive");
CSS:
#element.hasactive:active {
background:blue;
}
2) 阻止默认的 mousedown 功能(事件状态):
编辑:显然,这只适用于 Firefox。
JS:
document.getElementById("element").onmousedown = function(event) {
event.preventDefault();
}
3) 删除带有 css 规则的样式元素
HTML:
<style id="activestyle">
#element:active {
/*Your code here*/
}
</style>
JS:
document.getElementById("activestyle").remove();
关于javascript - 删除 :active pseudo-class from an element,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22016522/