数组拼接在IE中引发错误

时间:2022-08-14 19:32:21

IE7 and IE8 are not letting me splice my array (Safari, Chrome, Firefox work):

IE7和IE8不让我拼接我的阵列(Safari,Chrome,Firefox工作):

        lzaCreateAd1.weatherArray = new Array();
        var jWeatherIcon = $('.weatherIcon');

        jWeatherIcon.bind('click', function (){
            var targetID = $(this).attr('id') + 'Box',
            idVal = targetID.substr(5,1);

            var jTargetBox = $('#'+targetID);

            if (jTargetBox.hasClass('inactive')) {
                jTargetBox.removeClass('inactive').addClass('active');
                lzaCreateAd1.weatherArray.push(idVal);
            } else if (jTargetBox.hasClass('active')) {
                jTargetBox.removeClass('active').addClass('inactive');
                lzaCreateAd1.weatherArray.splice(lzaCreateAd1.weatherArray.indexOf(idVal),1);
            }
        });

IE throws the following error: "Object doesn't support this property or method" for this line:

IE抛出以下错误:“对象不支持此属性或方法”此行:

lzaCreateAd1.weatherArray.splice(lzaCreateAd1.weatherArray.indexOf(idVal),1);

lzaCreateAd1.weatherArray.splice(lzaCreateAd1.weatherArray.indexOf(idVal),1);

Any ideas? Or other ways to remove an array item by value? Thanks in advance!

有任何想法吗?或者按值删除数组项的其他方法?提前致谢!

1 个解决方案

#1


29  

Array.indexOf is not supported by Internet Explorer before version 9. You can use the jQuery's $.inArray utility function, or any other shim/polyfill you want instead.

在版本9之前,Internet Explorer不支持Array.indexOf。您可以使用jQuery的$ .inArray实用程序函数或您想要的任何其他填充/填充。

lzaCreateAd1.weatherArray.splice($.inArray(idVal, lzaCreateAd1.weatherArray) ,1);

See: http://api.jquery.com/jQuery.inArray/

请参阅:http://api.jquery.com/jQuery.inArray/

#1


29  

Array.indexOf is not supported by Internet Explorer before version 9. You can use the jQuery's $.inArray utility function, or any other shim/polyfill you want instead.

在版本9之前,Internet Explorer不支持Array.indexOf。您可以使用jQuery的$ .inArray实用程序函数或您想要的任何其他填充/填充。

lzaCreateAd1.weatherArray.splice($.inArray(idVal, lzaCreateAd1.weatherArray) ,1);

See: http://api.jquery.com/jQuery.inArray/

请参阅:http://api.jquery.com/jQuery.inArray/