jQuery:级联弹出窗口

时间:2009-06-24 16:30:57

标签: jquery popup tooltip show

我有以下代码来显示弹出式div:

<a href="#" id="pop1" rel="div#tt1">Click to show popup</a>
<div class="popupBlock" id="tt1">My popup content ...</div>

div最初是隐藏的,有一些jQuery代码,当点击pop1锚点时,我将它变为可见。这是我为此做的plgin:

(function($) {
$.fn.pop = function(options) {


    var defaults = {
        show: "click",
        tooltip: null
    };
    var options = $.extend(defaults, options);
    var target = $(this);
    var popup = $(target.attr("rel"));

    popup.css("visibility", "hidden").css("display", "none");
    target.click(function() {
        popup.css("visibility", "visible").css("display", "block");
        return false;
    });

    $('body').click(function() {
        popup.css("visibility", "hidden").css("display", "none");
        return false;
    });

    popup.click(function(event) {
        event.stopPropagation();
     });
};

所有似乎都是有序的,但是当我在div中添加一个控件时,整个事情就会中断,例如:

<div class="popupBlock" id="tt1">My popup content ...
       <span> some text here</span>
</div>

跨度不会触发div的click事件并隐藏div,这是我不想要的。 任何人都知道我需要做什么才能防止这种情况发生? 谢谢, V

1 个答案:

答案 0 :(得分:0)

var popup = $(target.attr("rel")).add($(target.attr("rel") > *));

var popup = $(target.attr("rel"), $(target.attr("rel") > *));