简体   繁体   English

如何使焦点属性保持不变,直到我单击另一个按钮

[英]How to make focus property stay until I click another button

I'm looking for a way to make the "focus" property stay until I click one of the other buttons. 我正在寻找一种方法来保持“焦点”属性,直到我单击其他按钮之一。

Normally, focus goes away even if I click anywhere else, but I need it to stay unless I click only one of the other buttons. 通常,即使我单击其他任何地方,焦点也会消失,但是除非我仅单击其他按钮之一,否则我需要保持焦点。

Solutions that include JavaScript are accepted as well, but only without using libraries. 也可以接受包含JavaScript的解决方案,但前提是不使用库。

 button:focus { color: red } 
 <div class="example"> <button>button 1</button> <button>button 2</button> <button>button 3</button> <button>button 4</button> </div> 

 $("button").focusin(function(){ $('button').css('color',''); // Remove Before set color to selected button $(this).css("color", "red"); // Set Color to Selected Button }); 
 button:focus { color: red } 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="example"> <button>button 1</button> <button>button 2</button> <button>button 3</button> <button>button 4</button> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 保留下拉菜单,直到单击按钮 - Make dropdown stay until button is clicked 如何使div停留在该位置,直到再次单击该链接? - How do I make the div stay there until the link is clicked again? 如何在单击时使:hover保持div处于悬停状态? - How do I make a div with :hover stay in hover state on click? 链接应保持按下状态,直到您单击另一个链接 - A link should stay pressed until you click another one 使链接保持下划线,直到仅单击其他按钮 - Make a link stay underlined until only other button is clicked 如何使一个div停留在另一个div的一侧? - How can I make a div stay to side of another div? 我如何才能使php action停留在此页面上,直到我退出JQuery为止? - How can I make php action stay on this page until I exit with JQuery? 当我单击另一个功能时,如何使按钮单击事件发生? - How do i make a button click event happen when i click on another function? 我为我的网页设置了焦点状态。 但即使在我完成点击按钮/链接之后,焦点仍然存在,除非我点击空格。 我该怎么做? - I styled focus state for my webpage. But even after I'm done clicking button/link, the focus stays, unless I click whitespaces. How do I make it go? 当我单击 Javascript 中另一个按钮的内容时,如何关闭一个按钮内容 - How do i make one button content close when i click another button's content in Javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM