2

我正在尝试使用 g:link 从 Grails .gsp 页面调用 jquery 函数。这可能吗?目前,我正在使用常规按钮(调用成功$( "#opener" )

<li><button id="opener">Export</button></li>

但我希望使用以下内容:

<div id="dialog" title="Export">
    <p>This is a sample dialog...</p>
</div>
<li><g:link class="export">
    <g:message code="default.new.label" args="[entityName]" />
</g:link></li>

这是我的功能:

<link rel="stylesheet"
href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
<style>
    .ui-dialog .ui-dialog-buttonpane .ui-dialog-buttonset { text-align: center; float: none; }
</style>
<script>

// increase the default animation speed to exaggerate the effect
$.fx.speeds._default = 1000;
$(function() {
    $( "#dialog" ).dialog({
        resizable: false,
        autoOpen: false,
        show: "blind",
        hide: "explode",
        buttons: {
            "OK!": function() {
                $( this ).dialog( "close" );
            },
            Cancel: function() {
                $( this ).dialog( "close" );
            }
        }
    });

    $( "#opener" ).click(function() {
        $( "#dialog" ).dialog( "open" );
        return false;
    });
});
</script>

我将不胜感激任何帮助。谢谢!

4

2 回答 2

2

在 Grails 2.5 中,您可以这样做:

<g:link onclick="alert('hello world')">
于 2015-11-01T14:03:28.583 回答
1

上次我需要这样做(Grails 1.3)时,我最终只使用了标准的 HTML<a></a>链接和onclick. 例如:

<a href="#" class="export" onclick="some_function();"><g:message code="default.new.label" args="[entityName]" /></a>

现在可能有一种方法可以使用 2.1.x 的 Grails taglib 来做到这一点,但如果我不知道的话。

于 2012-11-03T00:21:57.153 回答