Jquery对话框只打开一次 [英] Jquery dialog only opening once

查看:110
本文介绍了Jquery对话框只打开一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

All-
我知道这已经被问到了,但以前的解决方案似乎不适用于我的情况。

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

我有一个简单的表每行中都有一些记录,最后一列是删除超链接。我正在尝试使用该对话框弹出并确认删除。如果我使用对话框的div的显式名称(我将其正好位于表的div上方一个div)就可以完美地工作。我使用破坏第一,似乎解决了只打开一次问题,只要我命名对话框div。我试图普遍化代码,所以我宁愿远离明确命名对话框所在的div,而是参考prev div。这是第一次工作,但随后的点击不会:

I have a simple table with a number of records in each row, with the final column being a delete hyperlink. I'm trying to use the dialog to pop up and confirm delete. This works perfectly if I use explicit names of the div where the dialog is (I position it exactly one div above the div where the table is). I use a destroy first which seems to solve the "only opens once" problem, as long as as I name the dialog div. I'm trying to universalize the code, so I'd rather get away from explicitly naming the div where the dialog will live, but rather refer to the prev div. This works the first time, but subsequent clicks do not:

<code>
   $(".deleteLinkDiag a").livequery('click',function() {

    var myParent = $(this).parents("div:eq(0)"); //container div to be replaced
    var myDiag   = $(myParent).prev("div");     //one div before container div
    var urlLoad = $(this).attr("href");
    $(myDiag).dialog('destroy');
    $(myDiag).dialog({ 
            bgiframe: true,
            resizable: false,
            height:140,
            modal: true,
            autoOpen: false,
            overlay: {
                backgroundColor: '#000',
                opacity: 0.5
            },
            buttons: {
                    "Confirmz":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;
});
</code>

任何想法?

推荐答案

好的,希望这样可以帮助某人走下路。我实际上有两个问题:

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


  1. 如果你不破坏dialog(),那么它在DOM中并不存在在旧名下。这就是为什么第二次总是未定义的。

  2. 即使你摧毁对话框,你仍然找不到。这是因为当理论上 将对话框返回到初始化状态之前,它会通过将其放在身体标签之前的DOM底部。所以,它不再是prev或prevAll。

  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".

通过将对话框的名称设置为与调用div相同,附加Diag 。然后我可以跟踪它,无论jquery放在哪里。

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;
    });

这篇关于Jquery对话框只打开一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆