0

I have an issue related to click events on different modal divs.

I have a modal div 'A' which shows an overlay div with some info. This div is show by clicking i.e. a button A. So, when it's shown if i click outside the overlapped div, i want this to close.

I have another div 'B' which shows an overlay div with some other info. This div is show by clicking i.e. a button B. So, when it's shown if i click outside the overlapped div, i want this to close.

In both cases i use $(window).click() for managing them.

The question is that i need that when once i click on button 'A', it's corresponding div come up and if i click on button 'B' I want div 'A' close and div 'B' come up and viceversa.

how can i handle multiple clicks events for multiple modal divs?

Thanks.y

4

2 回答 2

1

这可能是一种凝视:

$('#buttonA").click(function(){
      $(#divA").show();
      $(#divB").hide();
})
于 2012-07-09T21:00:44.137 回答
1

我不确定这是否是您想要的,但是...

假设您的按钮和 div 属于“overlay”类,并且具有 Rolando 示例中的 ID(“buttonA”、“divA”;“buttonB”、“divB”;等):

$(".overlay").filter(":button").click(function() {
    var callid = /button(.+)/.exec($(this).attr("id"))[1];

    $("div.overlay[id$=" + callid + "]").show();
    $("div.overlay:not([id$=" + callid + "])").hide();
})

示例:http: //jsfiddle.net/KXeXj/

唯一的问题是“在 div 外部单击以关闭它”部分;我尝试使用$(":not(.overlay)").click(function() {$("div.overlay").hide()}),但这似乎不起作用,因为它只是将divs 隐藏在您单击的任何位置。

于 2012-07-10T15:01:46.763 回答