【发布时间】:2015-10-14 21:38:54
【问题描述】:
我在 GSP 页面中有脚本块,如下面的代码所示。但是脚本块没有响应。我没有在页面的控制台中打印 hello,而是收到错误 undefined operator $。可能是什么原因?
getSpecificQuestion.gsp
<html>
<head>
<script>
$('.index').click(function() {
console.log("hello")
});
</script>
<title> Test </title>
</head>
<body>
<div id="question">
<%= "question = $question"%>
</div>
<div id="indexButtons">
<g:each in="${(1..<11)}" var="i">
<input type="button" class="index" value="${i}"/>
</g:each>
</div>
</body>
</html>
【问题讨论】:
-
你能检查你是否有jquery插件吗?在 BuildConfig.groovy
-
是的,Neoryder,我已经安装了 jquery 插件。
-
将
$('.index').click...放入$(document).ready... -
也试过了,还是不行
-
gsp 是否使用布局