Javascript 属性列表后缺少}
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4726686/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
missing } after property list
提问by khr2003
I am trying to implement a content slider using jQuery in one of my website; however I keep getting this error:
我正在尝试在我的一个网站中使用 jQuery 实现一个内容滑块;但是我不断收到此错误:
missing } after property list
Here is my code:
这是我的代码:
<script type='text/javascript'>
featuredcontentslider.init({
id: 'slider1',
contentsource: ['inline', ''],
toc: '#increment',
nextprev: ['prev', 'next'],
revealtype: 'click',
enablefade: [true, 0.1],
autorotate: [true, 3000]
});
</script>
When I click on view source in Firefox I found that the last curly bracket is missing but in the file the code is fine, and using firebug debug console I got this error:
当我在 Firefox 中单击查看源代码时,我发现最后一个大括号丢失了,但在文件中代码很好,使用 firebug 调试控制台我得到了这个错误:
missing } after property list
I tried many things, searched for missing commas, eliminate most of the lines but could not find the source of the problem.
我尝试了很多东西,搜索缺少的逗号,消除了大部分行,但找不到问题的根源。
EDIT: Firebug points to this line:
编辑:Firebug 指向这一行:
});
as the one with error.
作为有错误的那个。
I just checked the script in IE8, Chrome and firefox and in all of the three broweser i get the code like this:
我刚刚在 IE8、Chrome 和 firefox 中检查了脚本,并且在所有三个浏览器中我都得到了这样的代码:
<script type='text/javascript'>
featuredcontentslider.init({
id: 'slider1',
contentsource: ['inline', ''],
toc: '#increment',
nextprev: ['prev', 'next'],
revealtype: 'click',
enablefade: [true, 0.1],
autorotate: [true, 3000]
); <---- notice the missing bracket
</script>
I also tried to write one line only like so:
我也试着像这样只写一行:
featuredcontentslider.init({ id: 'slider1' });
and still ended up with the same error. In localhost the script works fine, however in the actual website the script is functioning correctly.
并且仍然以相同的错误结束。在 localhost 中,脚本运行良好,但在实际网站中,脚本运行正常。
I am wondering is there a possibility that other js code in the page might affect the behaviour of this one?
我想知道页面中的其他 js 代码是否有可能影响此代码的行为?
回答by Jason S
Hmmm... this smells somewhat like a website cache error.
嗯……这有点像网站缓存错误。
Perhaps the }
was missing at one time, and even though you fixed it, your website is still serving the old file.
也许}
曾经丢失过,即使您修复了它,您的网站仍在提供旧文件。
Have you tried:
你有没有尝试过:
- clearing the cache in your browser? (to see if it's browser-side)
- using
curl
orwget
to view the raw javascript file (to see if there's a stale server-side cache)
- 清除浏览器中的缓存?(看看它是否是浏览器端)
- 使用
curl
或wget
查看原始 javascript 文件(查看是否存在陈旧的服务器端缓存)
回答by Chris
This usually happens, when a property list is accidentally closed by a ";". Take a look at the following example (which produces the same error):
这通常发生在属性列表被“;”意外关闭时。看看下面的例子(它会产生同样的错误):
$('#test').dialog({
autoOpen: true,
resizable: true,
draggable: true,
width:530,
modal: true,
closeOnEscape: true,
show: {
effect: 'blind',
duration: 1000
},
hide: {
effect: 'fold',
duration: 1000
});
});
The ); after
这 ); 后
hide: { ... });
should be removed.
应该被删除。
回答by khr2003
Ok I solved the problem by adding an extra curly bracket but I am not sure why that solved the issue. My final script looks like this:
好的,我通过添加一个额外的大括号解决了这个问题,但我不确定为什么会解决这个问题。我的最终脚本如下所示:
<script type='text/javascript'>
featuredcontentslider.init({
id: 'slider1',
contentsource: ['inline', ''],
toc: '#increment',
nextprev: ['prev', 'next'],
revealtype: 'click',
enablefade: [true, 0.1],
autorotate: [true, 3000]
} <--- notice the extra bracket
});
</script>
and it is cross-browser compatible :)
它是跨浏览器兼容的:)