5

我有一个编辑表单,我使用 Jquery 工具将其显示为叠加层。

在我的对象列表视图页面上,每个对象都有<a href="#" class="edit_button">Edit</a>. 所有这些都附加到相同的覆盖表单上:

        $(".edit_button[rel]").overlay({ top: '5px',
            fixed: false,

            mask: {
                color: '#ebecff',
                loadSpeed: 200,
                opacity: 0.9
            }
        });

编辑表单覆盖包含一个取消按钮:

<a href="#" class="cancel">Cancel</a>

如何使此取消按钮关闭覆盖?似乎我可以访问 Overlay API 对象的唯一方法是使用创建它的选择器 - 在这种情况下$('.edit').each(),因为我不知道是哪个触发了覆盖。

我真正想做的是:

$('.cancel').click(function(e){
    var target = e.originalTarget || e.srcElement;
    $(target).parent().parent().getOverlay().close();
});

但这不起作用。

有什么方法可以关闭覆盖而不做:

$(".edit_button[rel]").each(function() {
    $(this).overlay().close();
});

?

4

3 回答 3

2

You can easily add more closing elements inside the overlay simply by assigning the CSS class name "close" to them. These elements can be styled and positioned any way you like inside the overlay.

If you supply a value for the close configuration variable, the close element is not auto-generated and you need to define the closing element(s) yourself.

So if you put <a href="#" class="cancel close">Cancel</a> it should work.

于 2010-08-13T13:28:02.177 回答
1

To close the modal with JavaScript (automatically without clicking the close button):

$('#ID OF YOUR MODAL a.close').trigger("click");

or if you are in an iframe (like me), put parent. before the $.

于 2011-05-12T08:33:33.257 回答
1

Expanding on what Kras provided. If you only have one Overlay open at once (which logically you will do) then you can use this more generic approach perhaps:

  $('a.close').trigger('click');

I hope this helps!

于 2012-05-08T14:09:41.757 回答