修复ie9下模拟placeholder指令点击未穿透的问题

281 阅读1分钟

因兼容ie9自己写了一个placeholder指令,大致思路就是利用创建的div元素尽可能地拷贝input元素的样式,然后设置其位置属性使其全面覆盖input框,但是在使用过程中,有如下问题:

鼠标点击模拟区,并没有点击穿透至input使其聚焦。

解决方案:

// 原本背景色设置的是transparent
input.style.backgroundColor = 'transparent';
// 背景色设置为透明,个人理解相当于镂空,可点击穿透
input.style.backgroundColor = 'rgba(0,0,0,0)';