This是我的代码:
HTML
<div style="position:relative;">
<div style="position:absolute; top:0; left:0; z-index:40;" class="textBoxColor">My <span style='color:#c83243;'>custom</span> text</div>
<input type="text" style="position: relative; z-index: 50;" class="textBoxEmpty">
</div>
CSS
.textBoxEmpty, .textBoxColor
{
margin:0;
padding:0;
border:0;
line-height:20px;
font-size:20px;
height:20px;
width:340px;
color:#000000;
background-color:Transparent;
}
jQuery
$(".textBoxEmpty").focus(function() {
$(this).css('background', '#ffffff');
});
单击“输入”(在文本上方)我无法聚焦输入。但是,如果我在文本附近(右侧)单击,它就会获得焦点!
为什么?我该如何解决?
最佳答案
只需添加:
.textBoxEmpty:focus, .textBoxColor:focus {
background-color: #fff;
}
一切就绪。
关于jquery - 为什么这个输入框不触发 IE 上的焦点事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9329810/