Safari Javascriptparent.frames.length

发布于 2024-08-25 02:53:02 字数 416 浏览 3 评论 0原文

我使用以下代码从 Safari 中收到解析错误:

for (var i=0; i<parent.frames.length; i++){...}

doing

alert(parent.frames.length);

Works 并输出正确的值,即 5。

我也尝试过但失败了:

var len = parent.frames.length
alert(len); //Correct
for (var i=0; i<len; i++){...} //Parse Error

当我直接将此代码键入控制台时,它工作正常。而且它在其他浏览器中也能正常工作。

似乎有什么问题?

I get a parse error from Safari with this code:

for (var i=0; i<parent.frames.length; i++){...}

doing

alert(parent.frames.length);

works and outputs the correct value which is 5.

I also tried but failed:

var len = parent.frames.length
alert(len); //Correct
for (var i=0; i<len; i++){...} //Parse Error

When i type this code into the console directly, it works fine. And it also works fine in other browsers.

What seems to be the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

木落 2024-09-01 02:53:02

我找到了一种让它工作的方法,我只是在 < 之后添加了一个空格。

for(var i=0; i < parent.frames.length){...}

但我仍然很困惑为什么没有空格的会给出解析错误。

I found a way to make it work, i just added a space after <.

for(var i=0; i < parent.frames.length){...}

But i'm still stumped as to why the one without a space gives a parse error.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文