function loadLogoutBox() {
$('#logout_box').fadeIn("slow");
$(".main-wrapper").css({ // this is just for style
"opacity": "0.3"
});
$(".main-wrapper").disable();
$(".top-menu").attr('disabled', true);
}
任何帮助请!
function loadLogoutBox() {
$('#logout_box').fadeIn("slow");
$(".main-wrapper").css({ // this is just for style
"opacity": "0.3"
});
$(".main-wrapper").disable();
$(".top-menu").attr('disabled', true);
}
disabled
属性仅适用于form
元素的子集(input
,button
,select
和texarea
是我能想到的唯一几个)
$('.main-wrapper').find('input, textarea, button, select').each(function () {
$(this).prop('disabled', true);
});
您可以在包装器上放置一个遮罩 div
,以防止选择和锚标签的使用。将一个 div
添加到您的 HTML 中,然后将以下内容添加到您的 JS 和 CSS 中:
var mainWrapper = $('.main-wrapper')
mainWrapper.find('input, textarea, button, select').each(function () {
$(this).prop('disabled', true);
});
var mainWrapperPos = mainWrapper.position();
var mainWrapperHeight = mainWrapper.height();
var mainWrapperWidth = mainWrapper.width();
$('#cover').css({
'opacity':0.3,
'top': mainWrapperPos.top,
'left': mainWrapperPos.left,
'height': mainWrapperHeight,
'width': $('.main-wrapper').width()
});
#cover {
position:absolute;
}
注意:为了防止选项卡选择,您应该同时进行禁用和覆盖。此外,对于<a>
锚元素,您可以将href
设置为#
以防止使用选项卡。
,
来分隔textarea
、button
和select
将使它们选择所有这些元素,而不仅仅是.main-wrapper
内的元素。你需要在它们的前面加上.main-wrapper
,或者使用可选的上下文参数(参见这里)。 - ajp15243<div id="cover"></div>
CSS:
#cover {
position: absolute;
height: 100%;
width: 100%;
z-index: 1; /* make sure logout_box has a z-index of 2 */
background-color: none;
display: none;
}
jQuery:
function loadLogoutBox() {
$("#cover").css("display", "block");
$('#logout_box').fadeIn("slow");
$(".main-wrapper").css({ // this is just for style
"opacity": "0.3"
});
}
使用这种方法,当用户返回主屏幕时,您显然也需要添加一些jQuery来移除覆盖。
可以通过以下简单步骤完成:
$("#cover").css("display", "none");
在你的包裹器内添加一个覆盖层
,并将其置于所有元素的前面,但位于弹出窗口的后面。考虑以下HTML:
<div class="main-wrapper">
Here you have data
<span class="logout">[LOGOUT]</span>
<div class="popup">You have successfully logout</div>
<div class="overlay"></div>
</div>
再加上一些 CSS:
.main-wrapper {
background: green;
padding: 100px;
position: relative;
}
.overlay {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: #fff;
opacity: 0.7;
z-index: 5000;
display: none;
}
.popup {
background: red;
padding: 5px;
z-index: 6000;
position: absolute;
display: none;
}
$(function () {
$('.logout').on('click', function () {
$('.overlay').css('display', 'block');
$('.popup').css('display', 'block');
});
});
这段代码用于禁用具有类名 main-wrapper 的 div 元素中的所有输入元素。
$('.main-wrapper :input').attr('disabled', true);
与输入元素类似,您可以通过在标签名称中放置来禁用其他元素。
$('.main-wrapper :select').attr('disabled', true);
没有看到HTML代码,最有可能的问题是$(".main-wrapper")返回了一个没有disable方法的集合。你需要枚举并找到那些具有disable函数的对象,并调用它。
编辑:jQuery没有disable方法。你需要使用$object.prop('disabled', true);来隐藏元素或禁用它们。
最简单的方法是在弹出窗口后面创建一个覆盖层。我相信正确的CSS如下:
.overlay { display: none; position: absolute; background: #000; opacity: 0.3: top: 0; left: 0; width: 100%; height: 100%; }
您可能需要添加z-index。然后只需使用一些jQuery来淡入元素即可。
但是,此DIV不能用作容器。它必须是一个独立的元素。
对于格式不当,请原谅,我正在使用iPhone。
.contents()
或.contains()
- Jonny Sooter.main-wrapper
内添加一个带有absolute
定位和所需opacity
的覆盖层。 - user1823761