Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html Firefox/Internet explorer在选择标记中选择/突出显示项目的行为_Html_Css_Internet Explorer_Firefox_Html Select - Fatal编程技术网

Html Firefox/Internet explorer在选择标记中选择/突出显示项目的行为

Html Firefox/Internet explorer在选择标记中选择/突出显示项目的行为,html,css,internet-explorer,firefox,html-select,Html,Css,Internet Explorer,Firefox,Html Select,我注意到,在firefox中,当您单击箭头打开下拉列表的“选择”标记,然后指向一个选项时,正如我所预期的那样,该行以蓝色背景突出显示,这是正常的 但在Internet Explorer中,当您单击要选择的选项并将其变为选定选项时,蓝色高亮显示将一直保留,直到您单击“选择”标记之外的其他位置 有什么方法可以改变这种行为吗?一种方法是使用JavaScript。我已经使用jQuery使它变得更简单: 选择某个选项后,将从元素中移除焦点 要实现这一纯JavaScript,您需要使用onchange我遇到

我注意到,在firefox中,当您单击箭头打开下拉列表的“选择”标记,然后指向一个选项时,正如我所预期的那样,该行以蓝色背景突出显示,这是正常的

但在Internet Explorer中,当您单击要选择的选项并将其变为选定选项时,蓝色高亮显示将一直保留,直到您单击“选择”标记之外的其他位置


有什么方法可以改变这种行为吗?

一种方法是使用JavaScript。我已经使用jQuery使它变得更简单:

选择某个选项后,将从元素中移除焦点


要实现这一纯JavaScript,您需要使用
onchange

我遇到了这个问题,使用了James Donnelly的解决方案,但也希望在选择当前选项时防止突出显示剩余(在IE中尝试James的JSFIDLE或查看wilsonrufus的评论)

在选项上放置一个单击处理程序似乎可以解决以下问题:

var select = $('select');

select.change(function() {
    select.blur();
})

$('select option').click(function() {
    select.blur();
})

这将考虑选择新选项以及选择相同选项:

$('select > option').click(function () {
    $(this).parent().blur();
})

我猜这个插件能够满足你在IE中的要求,但我猜如果它没有改变的话$(这个);你救了我的命:)谢谢你!很抱歉,我打扰了您,但如果选择的选项与前一个相同(例如,我连续两次选择Hello),则焦点将保留在select上,蓝色突出显示将再次打开。有没有什么方法可以改变我对基于css的选项感兴趣,但这很有效
$('select > option').click(function () {
    $(this).parent().blur();
})