0

我正在使用 struts2-jquery,我正在尝试创建一个模式对话框以确认删除某些内容。我不知道如何传递 id 或“确定”来完成操作。

下面是我基于 struts2-jquery 创建对话框的代码:

<sj:dialog
    id="anchordialogconfirm"
    buttons="{
            'OK':function() {               
                //id of link is needed to c
                $(this).dialog('close');
            },
            'Cancel':function() {  $(this).dialog('close'); }
            }"
    resizable="false"
    autoOpen="false"
    modal="true"
    title="Remove?"
>
 Are you sure you want to remove it?
</sj:dialog>

<sj:a openDialog="anchordialogconfirm" id="71" cssClass="deleteemp">Delete</sj:a>

显然,如果我将 href='' 放入锚点,则对话框将打开到该链接,而不是获得模态确认对话框。

如何检索锚的 ID?我想要删除链接的 id 或至少禁止链接被使用,直到它“确定”这样做。

4

1 回答 1

1

您可以使用辅助变量来保存发送到对话框的数据。

在链接中,你会这样写:

<sj:a openDialog="anchordialogconfirm" onclick="aux=%{#attr.obj.id};" href="#">Remove<sj:a>

你在你的对话框中等待那个值:

<sj:dialog
            id="anchordialogconfirm"
            buttons="{
            'OK':function() {
            $('#main').load('yourUrl.action?id='+aux);
            $(this).dialog('close');
            },
            'Cancel':function() {  $(this).dialog('close'); }
            }"
            resizable="false"
            autoOpen="false"
            modal="true"
            title="Remove?"/>
于 2012-01-20T01:03:35.690 回答