Javascript <;部门>;单击页面其余部分后弹出隐藏窗口
(对不起我的英语) 我得到了一个弹出窗口(就像facebook上的通知)。我希望它隐藏后,点击页面的其余部分 按部就班地工作 你能帮我吗 代码: 要显示弹出窗口,我使用jqueryfadein JS:Javascript <;部门>;单击页面其余部分后弹出隐藏窗口,javascript,html,Javascript,Html,(对不起我的英语) 我得到了一个弹出窗口(就像facebook上的通知)。我希望它隐藏后,点击页面的其余部分 按部就班地工作 你能帮我吗 代码: 要显示弹出窗口,我使用jqueryfadein JS: 我的弹出窗口 页面的其余部分 尝试以下JSFIDLE 希望这是你的答案 Jquery $(document).mouseup(function (e) { var container = $("#login"); if (!container.is(e.target) //
我的弹出窗口
页面的其余部分
尝试以下JSFIDLE 希望这是你的答案 Jquery
$(document).mouseup(function (e)
{
var container = $("#login");
if (!container.is(e.target) // if the target of the click isn't the container...
&& container.has(e.target).length === 0) // ... nor a descendant of the container
{
container.hide();
}
});
试试这个!!给你,代码补充了最重要的部分。。你的javascript?我添加了我的javascript代码,这有点复杂,因为我有很多弹出窗口
#login {
background-color:@windows;
position:absolute;
width:413px;
height:190px;
z-index:110;
left:-189px;
top:43px;
overflow:visible;
line-height:normal;
display:none;
}
var active="";
function show_window(window) {
hide_active_window();
if(active==window) {
active="";
return;
}
active = window;
$('#'+window).fadeIn(200);
switch(window) {
case 'login':
$('#login_button').addClass("active");
break;
}
}
function hide_active_window() {
if(active=="") return;
$('#'+active).fadeOut(200);
switch(active) {
case 'login':
$('#login_button').removeClass("active");
break;
}
}
<html>
<head>
</head>
<body >
<div id="popup">My Popup</div>
<div id="restOfThePage" onClick="document.getElementById('popup').style.display='none';">Rest of the page</div>
</body>
</html>
$(document).mouseup(function (e)
{
var container = $("#login");
if (!container.is(e.target) // if the target of the click isn't the container...
&& container.has(e.target).length === 0) // ... nor a descendant of the container
{
container.hide();
}
});