最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - button color change by tab key press - Stack Overflow

programmeradmin0浏览0评论

I have a button and I want it to change to green when I access it by tab key. I have written the code for hover by mouse but I want that when a user a goes to the button using tab key then it should change the color.

I have a button and I want it to change to green when I access it by tab key. I have written the code for hover by mouse but I want that when a user a goes to the button using tab key then it should change the color.

Share Improve this question asked Aug 12, 2014 at 14:00 abhiabhi 311 silver badge6 bronze badges 3
  • please post you have so far – X-Pippes Commented Aug 12, 2014 at 14:00
  • What have you tried so far? and can you post some code for us to have a look at – Izzy Commented Aug 12, 2014 at 14:01
  • I think you need something like focus event – Aliaksei Bulhak Commented Aug 12, 2014 at 14:01
Add a ment  | 

1 Answer 1

Reset to default 6

Simply use the :focus pseudo selector

Demo Fiddle

button:focus{
    color:green;
}

More on :focus from MDN

The :focus CSS pseudo-class is applied when a element has received focus, either from the user selecting it with the use of a keyboard or by activating with the mouse (e.g. a form input).

You may also wish to give the button a tabindex attribute to control its tab order.

发布评论

评论列表(0)

  1. 暂无评论