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 に答える