2015-06-23 80 views
0

這裏是我的演示鏈接:http://jsfiddle.net/euavm0mo/1/關閉重疊點擊外DIV

我想點擊的表單元素外後關閉覆蓋。

現在它不會打開或關閉覆蓋,只要你點擊。

感謝

//Search 
$("#block-block-3 p").click(function() { 
    $(".searchform-overlay").addClass("header-search-active"); 

}); 

$(".close-btn").click(function() { 
    $(".searchform-overlay").removeClass("header-search-active"); 
}); 

}); 

// $(document).on("click", function (e) { 


// if (e.target.id == "searchform-container" || !$(e.target).closest("#searchform-container").length) { 
// $(".searchform-overlay").removeClass("header-search-active"); // 
//} 
+0

試試這個http://jsfiddle.net/euavm0mo/2/ – Sushil

+0

他希望它的關閉按鈕點擊不只是當關閉時表單元素之外點擊。 – TheOnlyError

回答

2

這應做到:http://jsfiddle.net/x0v91ena/

疊加關閉時,用戶不會對段落,輸入字段或其周圍的小包裝點擊。

$(document).ready(function() { 

    //Search 
    $("#block-block-3 p").click(function() { 
     $(".searchform-overlay").addClass("header-search-active"); 

    }); 
    $(".close-btn").click(function() { 
     $(".searchform-overlay").removeClass("header-search-active"); 
    }); 

    $(document).click(function (e) { 
     if ($(".searchform-overlay").hasClass("header-search-active")) { 
      if (!$('#search-form').is(e.target) && !$('input').is(e.target) && !$('#open').is(e.target)) { 
       $(".searchform-overlay").removeClass("header-search-active"); 
      } 
     } 
    }); 
}); 
+0

感謝百萬好友 – sani

+0

沒問題,我的榮幸:) – TheOnlyError

+0

好的回答夥伴 – Kumar