all
is not a built-in function or keyword, but why can I not call a function if it is named all
?
all不是内置函数或关键字,但如果它被命名为all,为什么我不能调用函数呢?
There is no error message in the debug console, and the function works if I rename it to all2
.
在调试控制台中没有错误消息,如果我将它重命名为all2,那么这个函数就可以工作。
Here is the code: tested in chrome and IE10
代码如下:在chrome和IE10中测试过
<!DOCTYPE html>
<head>
</head>
<body>
<script>
function all()
{
alert(1);
}
function all2()
{
alert(2);
}
</script>
<input type="button" value="all1" onclick="all()">
<input type="button" value="all2" onclick="all2()">
</body>
</html>
1 个解决方案
#1
7
This should have worked in chrome. However all
has been a method in IE until IE11.
这在chrome上应该行得通。然而,在IE11之前,所有这些都是IE中的一种方法。
[all is no longer supported. Starting with Internet Explorer 11, use getElementById. For info, see Compatibility changes.] Returns a reference to the collection of elements contained by the object. via http://msdn.microsoft.com/en-us/library/ie/ms537434(v=vs.85).aspx
不再支持所有内容。从Internet Explorer 11开始,使用getElementById。有关信息,请参见兼容性更改。返回对对象包含的元素集合的引用。通过http://msdn.microsoft.com/en-us/library/ie/ms537434(v = vs.85). aspx
I remember using it long ago, early javascript days something like this..
我记得很久以前用过它,早期的javascript就是这样。
for(i = 0; i < document.all.length; i++){
document.all(i) ...
}
It is deprecated in IE now and not implemented in most other browsers, although may still be considered a reserved name because of how wide reaching legacy code may be.
它在IE中被弃用,在大多数其他浏览器中都没有实现,尽管可能仍然被认为是一个保留的名称,因为它可能会有多广泛的遗留代码。
Update: I was able to track down another SO question, they answered it nicely.
更新:我找到了另一个SO问题,他们回答得很好。
document.all is available only on Internet Explorer, webkit and Opera.
文档。所有这些只能在Internet Explorer、webkit和Opera上使用。
On every other browser all is an undefined property of document object (and undefined is considered as a false value)
在所有其他浏览器上,所有文档对象都是未定义的属性(未定义的值被认为是一个假值)
As historical note: many (really many) years ago document.all was used to tell Internet Explorer from Netscape Navigator so if you meet a script that is checking if (document.all) ... I strongly suggest to find a better script :)
作为历史记录:许多(实际上许多)年前的文件。它们都是用来告诉Internet Explorer和Netscape Navigator的,所以如果你遇到一个正在检查if (document.all)的脚本……我强烈建议找一个更好的剧本:)
法布里奇奥Calderan
#1
7
This should have worked in chrome. However all
has been a method in IE until IE11.
这在chrome上应该行得通。然而,在IE11之前,所有这些都是IE中的一种方法。
[all is no longer supported. Starting with Internet Explorer 11, use getElementById. For info, see Compatibility changes.] Returns a reference to the collection of elements contained by the object. via http://msdn.microsoft.com/en-us/library/ie/ms537434(v=vs.85).aspx
不再支持所有内容。从Internet Explorer 11开始,使用getElementById。有关信息,请参见兼容性更改。返回对对象包含的元素集合的引用。通过http://msdn.microsoft.com/en-us/library/ie/ms537434(v = vs.85). aspx
I remember using it long ago, early javascript days something like this..
我记得很久以前用过它,早期的javascript就是这样。
for(i = 0; i < document.all.length; i++){
document.all(i) ...
}
It is deprecated in IE now and not implemented in most other browsers, although may still be considered a reserved name because of how wide reaching legacy code may be.
它在IE中被弃用,在大多数其他浏览器中都没有实现,尽管可能仍然被认为是一个保留的名称,因为它可能会有多广泛的遗留代码。
Update: I was able to track down another SO question, they answered it nicely.
更新:我找到了另一个SO问题,他们回答得很好。
document.all is available only on Internet Explorer, webkit and Opera.
文档。所有这些只能在Internet Explorer、webkit和Opera上使用。
On every other browser all is an undefined property of document object (and undefined is considered as a false value)
在所有其他浏览器上,所有文档对象都是未定义的属性(未定义的值被认为是一个假值)
As historical note: many (really many) years ago document.all was used to tell Internet Explorer from Netscape Navigator so if you meet a script that is checking if (document.all) ... I strongly suggest to find a better script :)
作为历史记录:许多(实际上许多)年前的文件。它们都是用来告诉Internet Explorer和Netscape Navigator的,所以如果你遇到一个正在检查if (document.all)的脚本……我强烈建议找一个更好的剧本:)
法布里奇奥Calderan