简体   繁体   中英

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.

If I do $.ClassNotty in the chrome console the js script is accessible, any idea?

 <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(...) .

$("#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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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