我试图在Grails 3.0应用程序中运行jQuery,我尝试在我的build.gradle文件中添加jQuery依赖项:
runtime "org.grails.plugins:jquery:1.11.1"
当我这样做时,应用程序构建失败了。我没有改变我的application.js文件,所以它仍然像这样:
//= require jquery-2.2.0.min
//= require bootstrap
//= require_tree .
//= require_self
if (typeof jQuery !== 'undefined') {
(function($) {
$('#spinner').ajaxStart(function() {
$(this).fadeIn();
}).ajaxStop(function() {
$(this).fadeOut();
});
})(jQuery);
}
在我的gsp页面中,我已经尝试过以下两种方法:
<g:javascript>
$( document ).ready(function() {
$( "#a" ).click(function( event ) {
alert( "Thanks for visiting!" );
});
});
</g:javascript>
并且
<g:javascript library='jquery'>
(function($){
$( document ).ready(function() {
$( "#a" ).click(function( event ) {
alert( "Thanks for visiting!" );
});
});
})(jQuery);
</g:javascript>
第一个错误提示"$未定义",第二个错误提示jQuery未定义。那么我应该如何在gsp页面中运行jQuery呢?
<asset:javascript src="jquery-2.2.0.min.js/>
添加到main.gsp中。我以为它已经被拉进来了,因为在页面的源代码中显示已经有它了。 - Justin Foley