简体   繁体   English

未捕获到的SyntaxError:意外令牌。 使用ClassNotty时

[英]Uncaught SyntaxError: Unexpected token . when using ClassNotty

I'm attempting to implement this example found here : ClassyNotty , I've imported the necessary references for the css and js. 我正在尝试实现以下示例: ClassyNotty ,我已经为css和js导入了必要的引用。

If I do $.ClassNotty in the chrome console the js script is accessible, any idea? 如果我在chrome控制台中执行$ .ClassNotty,则可以访问js脚本,知道吗?

 <h:head>
   <script  src="#{request.contextPath}/resources/js/jquery.classynotty.min.js"></script>
   <link rel="stylesheet" href="#{request.contextPath}/resources/css/jquery.classynotty.min.css"></link>
 </h:head>

<div>
  <a id="sample1" href="#">Messages!</a>
  <script>
    $(document).ready(function(){
     $("#sample1").click({
        $.ClassyNotty({
            title : 'Title',
            content : 'This is a notification'
           });
        });
     });                
  </script>
</div>

The error is because the .click() argument is an Object literal, {...} , which expects to contain key: value pairs rather than statements like $.ClassyNotty(...) . 该错误是因为.click()参数是对象文字{...} ,它期望包含key: value对,而不是$.ClassyNotty(...)类的语句。

$("#sample1").click({
    $.ClassyNotty({ /* ... */ });
  // ^ the parser expected a `:` here to separate a key and value
});

The argument to .click() should be a function instead, which does allow statements. .click()的参数应改为一个function ,该函数允许语句。

$("#sample1").click(function () {
  $.ClassyNotty({ /* ... */ });
});

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

相关问题 使用void()时未捕获的SyntaxError:意外的令牌) - Uncaught SyntaxError: Unexpected token ) when using void() Uncaught SyntaxError:使用本地主机时出现意外令牌 - Uncaught SyntaxError: Unexpected token when using localhost 当没有“:”时,“未捕获的SyntaxError:意外令牌:”吗? - “Uncaught SyntaxError: Unexpected token :” when there is no “:”? 这个Uncaught SyntaxError有什么错误:意外的令牌&lt;在jquery中使用eval时? - what error is this Uncaught SyntaxError: Unexpected token < when using eval in jquery? Uncaught SyntaxError:与烧瓶一起使用传单时出现意外令牌 - Uncaught SyntaxError: Unexpected token when using leaflet with flask 未捕获的SyntaxError:使用谷歌图表时无效或意外的令牌 - Uncaught SyntaxError: Invalid or unexpected token when using google chart Uncaught SyntaxError:在Codeigniter中使用jQuery Ajax时出现意外令牌 - Uncaught SyntaxError: Unexpected token when using jQuery Ajax in Codeigniter 使用JSON.parse时,&#39;未捕获的SyntaxError:意外的标记u&#39; - 'Uncaught SyntaxError: Unexpected token u' when using JSON.parse Uncaught SyntaxError: Unexpected token &lt; 使用 bootstrap js 时 - Uncaught SyntaxError: Unexpected token < when using bootstrap js 在 TypeScript 中导入时出现“Uncaught SyntaxError: Unexpected token {” - "Uncaught SyntaxError: Unexpected token {" when importing in TypeScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM