我的网站目前使用 AngularJS v1.2.8 的 debounce 指令。去抖动在 FF 和 Chrome 中很好,但延迟不会在 IE9 中发生。我对支持 IE9 有严格的要求,我无法升级到更新版本的 Angular。此代码的哪一部分不兼容 IE9?或者,如果有一个已知可在 IE9 中工作的 debounce 指令,将不胜感激。
当前的去抖指令:
angular.module('stuff.debounce', []).directive('ngDebounce', function($timeout) {
return {
restrive: 'A',
require: 'ngModel',
priority: 99,
link: function(scope, elm, attr, ngModelCtrl) {
if(attr.type === 'radio' || attr.type === 'checkbox') return;
elm.unbind('input');
var debounce;
elm.bind('input', function() {
$timeout.cancel(debounce);
debounce = $timeout( function () {
scope.$apply(function() {
ngModelCtrl.$setViewValue(elm.val());
});
}, attr.ngDebounce || 1000);
});
elm.bind('blur', function() {
scope.$apply(function() {
ngModelCtrl.$setViewValue(elm.val());
});
});
}
};
});