jquery - 为什么这个输入框不触发 IE 上的焦点事件?

标签 jquery html css input focus

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/

相关文章:

javascript - CSS over Ajax - 动态加载

javascript - 如何创建带有 knockout 绑定(bind)的自定义滚动条 (jScrollPane)?

jquery - typeahead.js 返回 "blank"数据集

php - PHP 中的 CSRF 保护

html - 如何将文本与图像垂直居中对齐

html - css 相同的类名获得相同的样式

html - 添加 li 的所有属性

css - 外部 CSS - 如何在 HTML 页面中编写/应用标签(初学者)

javascript - 检查用户是否点击了 iframe 嵌入的 youtube 视频

css - Bootstrap 列宽调整