Jquery dialog only opening once

前端 未结 2 383
抹茶落季
抹茶落季 2021-01-07 14:45

All- I know this has been asked, but the previous solutions don\'t seem to apply to my situation.

I have a simple table with a number of records in each row, with th

2条回答
  •  礼貌的吻别
    2021-01-07 15:23

    OKay, so hopefully this will help someone down the road. I actually had two problems going on:

    1. If you dont' destroy the dialog(), then it doesn't really exist in the DOM under the old name. That's why it was always undefined the second time through.
    2. Even if you DO destroy the dialog, you still can't find it. That's because when dialog theoretically returns it to pre-init state, it does so by dropping it at the bottom of the DOM right before the body tag. So, it's no longer in "prev" , or "prevAll".

    I got around this by just setting the name of the dialog box to be the same as the calling div, appended with "Diag". Then I can track it no matter where jquery puts it. Whew.

    $(".deleteLinkDiag a").livequery('click',function() {
                var urlLoad = $(this).attr("href");
                var myParent = $(this).parents("div:eq(0)"); //container div to be replaced
                var myDiag = myParent.attr('id') + 'Diag';
                $("#" + myDiag).dialog({
                        bgiframe: true,
                                resizable: false,
                                height:140,
                                modal: true,
                                autoOpen: false,
                                overlay: {
                                        backgroundColor: '#000',
                                        opacity: 0.5
                                },
                        buttons: {
                                        "Confirm":function()
                                        {
                                                myParent.load(urlLoad, function() { });
                                                $(this).dialog("close");
                                         },
                                        Cancel: function()
                                        {
                                                $(this).dialog("close");
                                        }
                                  },
                        close: function(ev, ui) {
                                $(this).dialog("destroy");
                        }
          });
         $("#" + myDiag).dialog('open');
        return false;
        });
    

提交回复
热议问题