[英]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.