【问题标题】:Grails g:link to call jquery functionGrails g:链接到调用jquery函数
【发布时间】:2012-10-23 16:06:23
【问题描述】:

我正在尝试使用 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>

如果有任何帮助,我将不胜感激。谢谢!

【问题讨论】:

    标签: jquery grails gsp


    【解决方案1】:

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

    <g:link onclick="alert('hello world')">
    

    【讨论】:

      【解决方案2】:

      上次我需要这样做(Grails 1.3)时,我最终只使用了带有onclick 的标准 HTML &lt;a&gt;&lt;/a&gt; 链接。例如:

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

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

      【讨论】:

      • 我刚试过这个,我收到错误“Uncaught TypeError: object is not a function”。我在上面发布了我的功能。你能看出它有什么问题吗?
      • 您也可以发布您的相关 GSP 内容吗?
      • 我使用“id”而不是“onclick”解决了这个问题:,感谢您的帮助!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-11
      • 2016-01-02
      • 1970-01-01
      相关资源
      最近更新 更多