Struts-jquery对话框确认+链接ID

时间:2011-07-21 16:33:32

标签: jquery struts2 modal-dialog confirmation

我正在使用struts2-jquery,我正在尝试创建一个模态对话框,以便确认删除内容。我不知道如何传递id或'OK'来完成动作。

下面是我根据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,或者至少禁止链接被使用,直到“OK”为止。

1 个答案:

答案 0 :(得分: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?"/>