IE< = 8 .splice()无效 [英] IE <= 8 .splice() not working

查看:203
本文介绍了IE< = 8 .splice()无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些简单的代码,你可以在我的小提琴中看到。它在所有浏览器和IE9中都能正常发出警报,但不能在IE8或7中正常发出警告。

I have some simple code you can see in my fiddle. It alerts properly in all browsers and IE9, but not IE8 or 7.

var func = function( x ) {
    var slice = [].slice,
        args = slice.call( arguments ),
        pass = args.splice(1);

    alert( pass );

};

func( 'a', 1, 2 );

编辑
使用解决方案我发布了我在这里使用的内容:
http://jsfiddle.net/7kXxX/4/

在我不知道有多少参数出现的情况下,我正在使用它,这就是为什么我使用参数

I am using this in a case where I don't know how many arguments are coming, which is why I'm using "arguments"

推荐答案

ECMAScript第3版标准需要第二个 deleteCount 参数:

Array.prototype.splice(start, deleteCount [, item1 [, item2[,...]]])

MSDN docs 显示IE如下此标准:

MSDN docs show that IE follows this standard:

arrayObj.splice(start, deleteCount, [item1[, item2[, . . . [,itemN]]]])

Firefox的SpiderMonkey允许第二个参数是可选的(与其他现代浏览器一样):

Firefox's SpiderMonkey allows the second argument to be optional (as do other modern browsers):

array.splice(index , howMany[, element1[, ...[, elementN]]])
array.splice(index[, howMany[, element1[, ...[, elementN]]]])

说明:


howMany
一个整数,表示要删除的旧数组元素的数量。如果howMany为0,则不删除任何元素。在这种情况下,
应指定至少一个新元素。如果没有指定
的howMany参数(上面的第二个语法,这是SpiderMonkey扩展名),则删除索引后的所有元素

howMany An integer indicating the number of old array elements to remove. If howMany is 0, no elements are removed. In this case, you should specify at least one new element. If no howMany parameter is specified (second syntax above, which is a SpiderMonkey extension), all elements after index are removed.

来源:

  • http://bclary.com/2004/11/07/#a-15.4.4.12
  • http://msdn.microsoft.com/en-us/library/wctc5k7s%28v=VS.85%29.aspx
  • https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/splice

这篇关于IE< = 8 .splice()无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆