在控制台上得到错误,表明此代码有问题。。
$.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>
有人能告诉我两者哪里出了问题吗?谢谢!-静态学习
在我看来,这个问题就像结尾的一个尾随括号。试试这个:
$.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.');
}
};
$.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.');
}
}
请从函数中删除此"):"字符。