我的 JavaScript 语法有什么问题?

发布于 2024-12-29 15:37:29 字数 443 浏览 2 评论 0原文

我正在编写一个 javascript 幻灯片,但 Firebug 告诉我语法有错误或其他错误,但我就是看不出出了什么问题! 这是代码片段:

<script language="javascript" type="text/javascript">

var data = new Array();

var data[0] = new Array();
var data[0]['id'] = 'example';
var data[0]['height'] = 190;

</script>

Firebug 说:

missing ; before statement  

var data[0] = new Array();

问题?好吧,我就是不明白问题出在哪里! 有人可以向我解释这个错误吗? 谢谢你!

I'm writing a javascript slideshow, but Firebug is telling me there's an error in the syntax, or something, but I just can't see what's wrong!
Here's the code snippet:

<script language="javascript" type="text/javascript">

var data = new Array();

var data[0] = new Array();
var data[0]['id'] = 'example';
var data[0]['height'] = 190;

</script>

Firebug says:

missing ; before statement  

var data[0] = new Array();

The problem? Well, I just don't understand where the problem is!
Could anyone explain the mistake to me?
Thank you!

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

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

发布评论

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

评论(2

书信已泛黄 2025-01-05 15:37:29

您不能声明数组索引。除了第一行之外,丢失所有的 var

You can't declare an array index. Lose the var on all but the first line.

苍风燃霜 2025-01-05 15:37:29

只保留第一个“var”语句,它将像这样工作:

var data = [];

data[0] = [];
data[0]['id'] = 'example';
data[0]['height'] = 190;

看看 http://jsfiddle.net/cmTBc/

Keep only the first "var" statement, it will work like this:

var data = [];

data[0] = [];
data[0]['id'] = 'example';
data[0]['height'] = 190;

Take a look http://jsfiddle.net/cmTBc/

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