javascript 删除选择的焦点
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15143946/
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
removing the focus of an select
提问by Tania Marinova
MY question may be stupid but I want to know if there is a chance to change this behaviour.
我的问题可能很愚蠢,但我想知道是否有机会改变这种行为。
I've noticed that when you click on the arrow of select tag to open the options of the dropdown and when you point at one option, it's highlighted in blue color background and that's OK.
我注意到当你点击选择标签的箭头打开下拉选项时,当你指向一个选项时,它会以蓝色背景突出显示,这很好。
But in IE when you click on the option you want to select and it becomes the selected option the blue highlighting remains until you click somewhere else outside the select tag (it's not that way in firefox - ). BUt i understood whAT I should do and removed the focus from the element when an option has been selected.
但是在 IE 中,当您单击要选择的选项并且它成为所选选项时,蓝色突出显示会一直保留,直到您单击 select 标签之外的其他位置(在 firefox 中不是这样 - )。但是我明白我应该做什么,并在选择了一个选项时从元素中移除了焦点。
$('select').change(function() {
$(this).blur();
})
But still one little problem stays - if the option that is selected is the same as the previous (for example I choose one element two times consecutively)the focus stays on select and the blue highlighting is on again. Is there any way to change that
但仍然存在一个小问题 - 如果选择的选项与前一个相同(例如我连续两次选择一个元素)焦点停留在选择上,蓝色突出显示再次亮起。有什么办法可以改变
回答by willrice
In IE11 (not sure about previous versions) you can remove the blue background from a focused select element with
在 IE11(不确定以前的版本)中,您可以使用以下命令从聚焦的选择元素中删除蓝色背景
select::-ms-value {background: none;}
回答by BingeBoy
Try this in the css:
在 css 中试试这个:
input:focus,
select:focus,
textarea:focus,
button:focus {
outline: none;
}
I think that's what you are looking for.
我想这就是你要找的。
回答by DreamTeK
You can set the selected dropdowns background colour in css with:
您可以在 css 中设置选定的下拉菜单背景颜色:
select:focus {
background: #fff;
}
As for removing the focus of the element I you are going to create more problems than you resolve and I would reconsider if it's necessary.
至于删除元素 I 的焦点,您将创建比您解决的更多的问题,如果有必要,我会重新考虑。