简体   繁体   English

Grails的: <script> vs. <g:javascript>

[英]Grails: <script> vs. <g:javascript>

Can anyone please explain the difference between these two tags and how Grails sees one vs. the other? 谁能解释这两个标签之间的区别以及Grails如何看待一个标签与另一个标签? I have a table with click and hover effects which don't seem to happen when I import jquery using: 我有一个带有单击和悬停效果的表,当我使用以下命令导入jquery时似乎没有发生:

<g:javascript library="jquery" />

but do when I do this: 但是,当我这样做时:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

and I want to use the previous tag because other Grails tags such and remote forms rely on it for their built in ajax capabilities. 我想使用以前的标记,因为其他Grails标记(例如,远程表单)和远程表单依赖于其内置的ajax功能。

The first is the custom Grails tag and tries to load the Javascript library by that name. 第一个是自定义的Grails标记,并尝试使用该名称加载Javascript库。 If you're using the Resources plugin, then the call delegates to that for loading of the library. 如果您使用的是Resources插件,则该调用将委派给该资源以加载库。 Take a look at JavascriptTagLib.groovy to see what the custom tag does. 看一看JavascriptTagLib.groovy,看看自定义标签的作用。

The latter is just the regular HTML script element, and attempts to fetch a script at the location provided. 后者只是常规的HTML脚本元素,并尝试在提供的位置获取脚本。

The issue you're running into may slightly depend on the version of Grails you are running too. 您遇到的问题可能也取决于您所运行的Grails的版本。 Looks like 'jQuery' is not a valid library in Grails 1.3.x: 看起来'jQuery'在Grails 1.3.x中不是有效的库

library (optional) - The name of the library to include. 库(可选)-要包括的库的名称。 Either "prototype", "scriptaculous", "yahoo" or "dojo" “原型”,“文字”,“ yahoo”或“ dojo”

You may want to make sure that your path is correct and you either have the Grails jQuery plugin installed, or you have the library in your web-app/js directory. 您可能需要确保路径正确,并且已经安装了Grails jQuery插件 ,或者在web-app/js目录中具有了库。 Grails 2.x comes with jQuery by default, but older versions did not. 默认情况下,Grails 2.x随jQuery一起提供,但较早的版本没有。

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

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