all is not a built-in function or keyword, but why can I not call a function if it is named all?
There is no error message in the debug console, and the function works if I rename it to all2.
Here is the code: tested in chrome and 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>
Run Code Online (Sandbox Code Playgroud)
这应该在chrome中起作用.但是all在IE11之前一直是IE中的一种方法.
[所有不再受支持.从Internet Explorer 11开始,使用getElementById.有关信息,请参阅兼容性更改.]返回对象包含的元素集合的引用.通过http://msdn.microsoft.com/en-us/library/ie/ms537434(v=vs.85).aspx
我记得很久以前使用它,早期的javascript天就像这样......
for(i = 0; i < document.all.length; i++){
document.all(i) ...
}
Run Code Online (Sandbox Code Playgroud)
它现在在IE中已弃用,并未在大多数其他浏览器中实现,但由于遗留代码可能有多广,因此仍可能被视为保留名称.
更新:我能够找到另一个SO问题,他们很好地回答了.
document.all仅在Internet Explorer,webkit和Opera上可用.
在每个其他浏览器上,所有都是文档对象的未定义属性(并且undefined被视为false值)
作为历史记录:很多(很多)几年前,document.all被用来告诉Netscape Navigator的Internet Explorer,所以如果你遇到一个检查if(document.all)的脚本......我强烈建议找一个更好的脚本: )
| 归档时间: |
|
| 查看次数: |
252 次 |
| 最近记录: |