Fork me on GitHub

IE9下解决disable不能脱离焦点问题

又一个月没来了,真是忙坏了。~ 记录下最近项目中遇到的问题,防备以后再次遇到,也方便同遇到的人吧~

//View Code
<input id="txtProjectManager" name="txtProjectManager" type="text" value="" maxlength="100"
                    style="width: 130px;" disabled=disabled/>

Js代码

//处理IE9 disable焦点无法移除bug Created by Isaac start
function addDivForDisableControl(selector) {
    selector.wrap("<div onmousedown='return false;' onmousemove='return false;' style='display: inline'></div>");
}
function removeDivForDisableControl(selector) {
    selector.unwrap();
}

//调用方式
$(window).load(function () {
    addDivForDisableControl($('[disabled=disabled]'));
});

解决思路,因为是ie9本身的bug,我们只能通过遮罩层来不允许其获得焦点,就OK了,当然取值的时候,要注意移除遮罩层哦~~

posted @ 2013-04-22 15:32  IsaacZhang  阅读(245)  评论(2编辑  收藏  举报