在Internet Explorer 11中,当下拉菜单在输入字段上打开时,包含一些键入文本的输入字段内闪烁的文本光标仍然可见。我希望光标在菜单后(例如在Chrome / Firefox / Safari中)会被遮盖。
当我在输入字段中输入随机文本然后将鼠标悬停在下拉按钮上以提示下拉菜单在输入字段上切换打开时,我发现了这个问题。我试过调整输入字段的z-index,但无法使该光标消失。
如何使该光标对IE11保持隐藏状态?
截屏:
摘要:
.dropbtn {
background-color: #4CAF50;
color: white;
padding: 16px;
font-size: 16px;
border: none;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {
background-color: #ddd;
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown:hover .dropbtn {
background-color: #3e8e41;
}
<h2>Hoverable Dropdown</h2>
<p>Move the mouse over the button to open the dropdown menu.</p>
<div class="dropdown">
<button class="dropbtn">Dropdown</button>
<div class="dropdown-content">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</div>
<br>
<hr>
<br>
<form action="/action_page.php">
First name: <input type="text" name="FirstName"><br>
<input type="submit" value="Submit">
</form>
答案 0 :(得分:2)
显然,在IE中,光标绘制在窗口表面上。您所要做的就是在blur()
上mouseenter
的activeElement上触发.dropbtn
:
document.querySelector('.dropbtn').addEventListener('mouseenter', function(){
document.activeElement.blur();
})
.dropbtn {
background-color: #4CAF50;
color: white;
padding: 16px;
font-size: 16px;
border: none;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {
background-color: #ddd;
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown:hover .dropbtn {
background-color: #3e8e41;
}
<h2>Hoverable Dropdown</h2>
<p>Move the mouse over the button to open the dropdown menu.</p>
<div class="dropdown">
<button class="dropbtn">Dropdown</button>
<div class="dropdown-content">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</div>
<br>
<hr>
<br>
<form action="/action_page.php">
First name: <input type="text" name="FirstName"><br>
<input type="submit" value="Submit">
</form>