简体   繁体   English

未捕获的语法错误意外令牌。 jQuery的

[英]uncaught syntaxerror unexpected token . jquery

First of all let me say I'm new to jQuery. 首先,我要说我是jQuery新手。 I've tried to search for this error on StackOver flow but did not get any answers. 我试图在StackOver流上搜索此错误,但没有得到任何答案。 I've created a function in jQuery but this is the error I'm getting from Chrome. 我已经在jQuery中创建了一个函数,但这是我从Chrome浏览器中收到的错误。 uncaught syntaxerror unexpected token . 未捕获的语法错误意外令牌。 jquery jQuery的

jQuery.fn.viewC = function(){
    return this.each(function(){
    alert("something");
    });
}

And I'm trying to call this from another function like this 我试图从另一个这样的函数中调用它

$("#sourceId").click(function() {
    $(this).viewC();
})

Is this the correct way to call a function? 这是调用函数的正确方法吗? And finally what is difference between 最后,两者之间有什么区别

_tabChanged : function(container) {
    //some code
},

and

jQuery.fn.viewC = function(){
    //some code
}

Are both the same ways to create a function? 两种创建函数的方式相同吗?

It is a little strange you are using both $ and jQuery in one piece of code. 您在一个代码中同时使用$jQuery有点奇怪。 Usually you would use $ to refer to jQuery. 通常,您将使用$来引用jQuery。

Try this: 尝试这个:

$.fn.viewC = function(){
  return this.each(function(){
  alert("something");
});

} }

Also, I am not sure if this.each will work (not if it is meant to be jQuery). 另外,我不确定this.each是否会工作(如果是jQuery,则不确定)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM