按下按键时更改类名
我想要这样做,当我按下按钮 A 时,元素的类将获得与鼠标悬停时相同的“类”。 (在 CSS 中我有 kay:hover 来改变样式)。
但我需要将指定类名的键更改为 key:hover 。 就像 onkeydown 将样式从“key C”更改为“key:hover C”:/
我如何实现这种效果?
抱歉,如果我解释得不好:P
I want to do so that when I press the button A the class of the element gets the same "class" as it gets on mouse over. (in CSS i have kay:hover to change the style ).
But I need to change the key to key:hover for specified classname.
Like onkeydown change style from "key C" to "key:hover C" :/
How do i achieve this effect?
Sorry if i explained badly :P
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以执行类似“
Where 65 is the keycode for the letter 'a'”
的操作,然后添加
将类设置回释放“a”按钮时的状态。
You can do something like
Where 65 is the keycode for the letter 'a'
Then add
to set the class back to what it was when you release the 'a' button.
已解决我刚刚做了
KEYDOWN: document.getElementById("keyC").className = "key2 C";
KEYUP: document.getElementById("keyC").className = "key C";
SOLVED i just did
KEYDOWN: document.getElementById("keyC").className = "key2 C";
KEYUP: document.getElementById("keyC").className = "key C";