我正在尝试实现此处的示例:ClassyNotty ,我已经导入了 css 和 js 的必要引用。
如果我在 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>
最佳答案
错误是因为 .click()
参数是一个对象字面量,{...}
,它期望包含 key: value
对而不是像 $.ClassyNotty(...)
这样的语句。
$("#sample1").click({
$.ClassyNotty({ /* ... */ });
// ^ the parser expected a `:` here to separate a key and value
});
.click()
的参数应该是一个函数
,它允许语句。
$("#sample1").click(function () {
$.ClassyNotty({ /* ... */ });
});
关于javascript - 使用 ClassNotty 时未捕获的语法错误 : Unexpected token .,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25531712/