我正在使用结构化的 javascript 代码,它在我的电脑上运行良好。但是当我将它添加到 jsFiddle 时,它给了我以下错误:
SyntaxError: Unexpected token :
我的代码是这样的:
var StentGallery = {
gallery: null,
init : function(){
this.gallery = jQuery('#gallery-list-ui');
this.resizeImage();
}
}
(...)
}
有谁知道为什么这在 jsFiddle 中不起作用?
在这里查看我的 fiddle :https://jsfiddle.net/smyhbckx/
最佳答案
您的代码中存在语法错误:
var StentGallery = {
gallery: null,
init : function(){
this.gallery = jQuery('#gallery-list-ui');
this.resizeImage();
} // <----- this is prematurely closing your object
},
resizeImage: function(){
...
要解决这个问题,只需删除那个括号:
var StentGallery = {
gallery: null,
init : function(){
this.gallery = jQuery('#gallery-list-ui');
this.resizeImage();
},
resizeImage: function(){
...
关于javascript - 为什么 jsfiddle 给我错误 "SyntaxError: Unexpected token :"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34120947/