Javascript 通过javascript删除或禁用浏览器的焦点边框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3015523/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 02:56:10  来源:igfitidea点击:

Remove or disable focus border of browser via javascript

javascripthtmlcsstabindex

提问by helle

Does anybody know how to disable or manipulate the (in most browsers) dashed border of a dom-element if it has the focus in a tabindex order?

有谁知道如何禁用或操作(在大多数浏览器中)dom 元素的虚线边框,如果它具有 tabindex 顺序的焦点?

I want to build my own style for a focused element, but it would be great to use the existing feature, because with tabindex it is possible to bind keydown event to the dom-element.

我想为重点元素构建自己的样式,但使用现有功能会很棒,因为使用 tabindex 可以将 keydown 事件绑定到 dom 元素。

回答by Gabriele Petrioli

Just make a CSS rule for the elements you want that have outline:none;

只需为您想要的元素制定一个 CSS 规则 outline:none;

回答by goker.cebeci

CSS trick:

CSS技巧:

:focus { outline: none; }

回答by hsyl20

With Firefox 53.0, if I disable the outline with one of the proposed solution, Firefox displays the default one.

对于 Firefox 53.0,如果我使用建议的解决方案之一禁用大纲,Firefox 会显示默认的大纲。

However, if I use a blank color, it doesn't detect that the outline is hidden:

但是,如果我使用空白颜色,则不会检测到轮廓已隐藏:

input:focus{
   outline: 1px solid rgba(255,255,255,1);
}

回答by Mayur bhalgama

input::-moz-focus-inner { border: 0; }

回答by rotamota

a {
outline: 0;
}

a: hover,
a: active,
a: focus {
     outline: none;
}

input::-moz-focus-inner {
border: 0;
}

回答by Mahendra Kulkarni

:focus state- Set the outline propertyto 0px solid transparent;

:focus state- 将轮廓属性设置为 0px 实心透明;

回答by slva2000

$(function() {
     $('a').click(function() { $(this).blur(); });
     $('input').click(function() { $(this).blur(); });
});

Don't use CSS disable focus: http://outlinenone.com/This use other users.

不要使用 CSS 禁用焦点:http: //outlinenone.com/这使用其他用户。

回答by Boris Delormas

Using jQuery you can do

使用 jQuery 你可以做到

$("#nav li a").focus(function(){
  $(this).blur();
});