jQuery   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了jquery – 使用什么而不是Object.keys()?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我需要在 Jquery中找到可以在IE8和真实浏览器中工作的东西.我是Jquery的新手,以下是我在现代浏览器中运行的代码
$('#FIELD_'+office_id).on('change',function(){
    offices = $(this).val();
for(var i=0; i<=Object.keys(southland.address).length;i++){
        if(offices == Object.keys(southland.address)[i]){
            address = southland.address[offices]Object.keys(southland.address[offices])[0]];
        }
    }
@H_262_4@其中southland.address来自外部阵列.这在Chrome,IE10和FF中完美无缺,我能为IE8做些什么吗?

解决方法

要在旧版浏览器中支持Object.keys,您可以使用以下代码段: @H_262_4@https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys#Compatibility

if (!Object.keys) {
  Object.keys = (function () {
    var hasOwnProperty = Object.prototype.hasOwnProperty,hasDontEnumbug = !({toString: null}).propertyIsEnumerable('toString'),dontEnums = [
          'toString','toLocaleString','valueOf','hasOwnProperty','isPrototypeOf','propertyIsEnumerable','constructor'
        ],dontEnumsLength = dontEnums.length;

    return function (obj) {
      if (typeof obj !== 'object' && typeof obj !== 'function' || obj === null) throw new TypeError('Object.keys called on non-object');

      var result = [];

      for (var prop in obj) {
        if (hasOwnProperty.call(obj,prop)) result.push(prop);
      }

      if (hasDontEnumbug) {
        for (var i=0; i < dontEnumsLength; i++) {
          if (hasOwnProperty.call(obj,dontEnums[i])) result.push(dontEnums[i]);
        }
      }
      return result;
    };
  })();
}
@H_262_4@或者这个polyfill(包括其他垫片):

@H_262_4@https://github.com/kriskowal/es5-shim/

大佬总结

以上是大佬教程为你收集整理的jquery – 使用什么而不是Object.keys()?全部内容,希望文章能够帮你解决jquery – 使用什么而不是Object.keys()?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。