SyntaxError:missing;在声明之前 - jQuery ContentHover

时间:2015-02-21 18:26:12

标签: javascript jquery twitter-bootstrap jquery-plugins

在控制台上获取错误,说这段代码有问题..

$.fn.contenthover = function(method) {  
    if (methods[method]) {
        return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
    } else if (typeof method === 'object' || !method) {
        return methods.init.apply(this, arguments);
    } else {
        $.error('Method '+ method +' does not exist in contentHover plugin.');
    }
});

这也是HTML

<script>
$(document).ready(function(){
    $('#d1').contenthover({
        overlay_background:'#000',
        overlay_opacity:0.5
    });
});
</script>

有人能告诉我两个地方出错了吗?谢谢! - stilllearning

2 个答案:

答案 0 :(得分:0)

     $.fn.contenthover = function(method) {  
if (methods[method]) {
    return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
    return methods.init.apply(this, arguments);
} else {
    $.error('Method '+ method +' does not exist in contentHover plugin.');
} 
}         

请从功能中删除此“):”字符。

答案 1 :(得分:0)

对我来说,这个问题在最后看起来像一个尾随的括号。试试这个:

$.fn.contenthover = function(method) {  
    if (methods[method]) {
        return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
    } else if (typeof method === 'object' || !method) {
        return methods.init.apply(this, arguments);
    } else {
        $.error('Method '+ method +' does not exist in contentHover plugin.');
    }
};