解决Edge不兼容onpropertychange的方法

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

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

    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");

    });spa

为了使IE9-IE十一、以及谷歌所有支持,能够给他绑定两个方法。prototype

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

}input

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

alert("兼容IE");io

}function