gpt4 book ai didi

javascript - IE <= 8 .splice() 不起作用

转载 作者:行者123 更新时间:2023-12-03 07:01:08 25 4
gpt4 key购买 nike

我有一些简单的代码,您可以在 my fiddle 中看到。它可以在所有浏览器和 IE9 中正确发出警报,但不能在 IE8 或 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/

我在不知道有多少参数出现的情况下使用它,这就是我使用“参数”的原因

最佳答案

ECMAScript 3rd edition standard需要第二个 deleteCount 参数:

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

MSDN docs表明 IE 遵循此标准:

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

Firefox 的 SpiderMonkey 允许 second argument to be optional (与其他现代浏览器一样):

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

描述:

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.

来源:

关于javascript - IE <= 8 .splice() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8332969/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com