解决Edge不兼容onpropertychange的方法

新版本的Edge浏览器不支持原IE自带的onpropertychange方法,需要使用oninput方法,而oninput方法在Edge中又无法使用bind和on绑定function。因此需要特殊处理才能使用oninput方法

Element.prototype.addEvent = function(type,fn){

    if(window.addEventListener){
      this.addEventListener(type, fn);
    }else if(window.attachEvent){
      this.attachEvent('on' + type, fn);
    }else{
      this['on' + type] = fn;
    }
}
var btn = document.getElementById('test1');
    btn.addEvent('input', function(){
       //需要执行的方法
       alert("dd");

    });

为了使IE9-IE11、以及谷歌全部支持,可以给他绑定两个方法。

document.getElementById('test1')['oninput']=function(){
alert("兼容谷歌和Edge");

}

$("#test1").bind("propertychange",function (){

alert("兼容IE");

}

猜你喜欢

转载自blog.csdn.net/qq_35921773/article/details/80625999
今日推荐