javascript如何实现真正的模态窗口? 网上普遍都是说三层锁屏,但这不是真正的模态窗口。真正的模态窗口不但能禁止背景输入,而且还要能中断代码执行,直到点击确认或取消后,代码才继续执行请问这个在javascript中应该怎么实现呢?求例子 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>基于JQuery的JS遮罩层效果</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script> <script type="text/javascript"> function showDiv() { document.body.style.overflow = 'hidden'; var docHeight = Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight); var docWidth = Math.max(document.documentElement.scrollWidth, document.documentElement.clientWidth); var _div = document.createElement('div'); _div.className = 'divClass'; _div.setAttribute('id', 'divId'); document.body.appendChild(_div); document.getElementById('divId').style.width = docWidth + 'px'; document.getElementById('divId').style.height = docHeight + 'px'; var _divAlert = document.createElement('div'); _divAlert.className = 'divalert'; _divAlert.id = 'divalert'; document.body.appendChild(_divAlert); document.getElementById('divalert').style.left = (document.documentElement.clientWidth - 200)/2 + 'px'; document.getElementById('divalert').style.top = (document.documentElement.clientHeight - 100)/2 + 'px'; var _divContent = document.createElement('div'); _divContent.id = 'divcontent'; _divAlert.appendChild(_divContent); var _divbtn = document.createElement('div'); _divbtn.id = 'divbtn'; var _btn = document.createElement('input'); _btn.type = 'button'; _btn.value = '确定'; _btn.id = 'btn'; _divbtn.appendChild(_btn); _divAlert.appendChild(_divbtn); document.getElementById('btn').onclick = function() { document.getElementById('divId').style.display = 'none'; document.getElementById('divalert').style.display = 'none'; document.body.style.overflow = 'auto'; } } function resizeDiv() { var docHeight = Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight); var docWidth = Math.max(document.documentElement.scrollWidth, document.documentElement.clientWidth); document.getElementById('divId').style.width = document.documentElement.clientWidth + 'px'; document.getElementById('divId').style.height = document.documentElement.clientHeight + 'px'; } window.onload = function() { showDiv(); } window.onresize = resizeDiv; </script> <style type="text/css"> body { margin:0; padding:0; } .divClass { position:absolute; left:0; top:0; background-color:#ccc; z-index:0; } .divalert { position:absolute; z-index:2000; width:200px; height:100px; border:1px solid #666; background-color:#fff; } #divcontent { height:60px; } #divbtn { height:40px; background-color:#ddd; text-align:center; } #btn { border:1px solid #000; margin-top:10px; } </style> </head> <body> <div style='height:1000px;'>fsfs</div> </body> </html> 老赵有个异步执行的类库Jscex,可以去试下http://jeffreyzhao.cnblogs.com/ 根本就不行,你试试改成这样后面的alert会不会马上出现?我要的效果是点了确定后才继续执行后面的alertwindow.onload = function() { showDiv(); alert(1);} 模拟的都无法挂起js代码执行,都是基于回调的机制。showModalDialog方法可以,但是低版本的firefox和有些浏览器不支持 靠JS模拟是实现不了的..只有IE以及部分浏览器自带的showModalDialog方法可以.. google chrome打印的问题 在线音乐只能自己电脑播放,别人浏览我发布的网页时不能播放。 js第8讲 JavaScript的数组的声明与应用 JQ 筛选添加样式,在线等。 层拖拽问题请教高手 [100分]求一正则表达式 怎样用嵌入对象的方式打开powerpoint(.ppt)文件 <a href="javascript:history.back()">返回</a>为啥提示网页过期! textarea能不能加上MAXLENGTH那样的属性。 如何取消定时触发? IE10 下如何保证离开iframe窗口仍能保持选中区? 牛人不牛人的都可以来,学习的好机会!关于正则替换正则问题
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>基于JQuery的JS遮罩层效果</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script type="text/javascript">
function showDiv() {
document.body.style.overflow = 'hidden';
var docHeight = Math.max(document.documentElement.scrollHeight,
document.documentElement.clientHeight);
var docWidth = Math.max(document.documentElement.scrollWidth,
document.documentElement.clientWidth);
var _div = document.createElement('div');
_div.className = 'divClass';
_div.setAttribute('id', 'divId');
document.body.appendChild(_div);
document.getElementById('divId').style.width = docWidth + 'px';
document.getElementById('divId').style.height = docHeight + 'px';
var _divAlert = document.createElement('div');
_divAlert.className = 'divalert';
_divAlert.id = 'divalert';
document.body.appendChild(_divAlert);
document.getElementById('divalert').style.left = (document.documentElement.clientWidth - 200)/2 + 'px';
document.getElementById('divalert').style.top = (document.documentElement.clientHeight - 100)/2 + 'px';
var _divContent = document.createElement('div');
_divContent.id = 'divcontent';
_divAlert.appendChild(_divContent);
var _divbtn = document.createElement('div');
_divbtn.id = 'divbtn';
var _btn = document.createElement('input');
_btn.type = 'button';
_btn.value = '确定';
_btn.id = 'btn';
_divbtn.appendChild(_btn);
_divAlert.appendChild(_divbtn);
document.getElementById('btn').onclick = function() {
document.getElementById('divId').style.display = 'none';
document.getElementById('divalert').style.display = 'none';
document.body.style.overflow = 'auto';
}
}
function resizeDiv() {
var docHeight = Math.max(document.documentElement.scrollHeight,
document.documentElement.clientHeight);
var docWidth = Math.max(document.documentElement.scrollWidth,
document.documentElement.clientWidth);
document.getElementById('divId').style.width = document.documentElement.clientWidth + 'px';
document.getElementById('divId').style.height = document.documentElement.clientHeight + 'px';
}
window.onload = function() {
showDiv();
}
window.onresize = resizeDiv;
</script>
<style type="text/css">
body { margin:0; padding:0; }
.divClass { position:absolute; left:0; top:0; background-color:#ccc; z-index:0; }
.divalert { position:absolute; z-index:2000; width:200px; height:100px; border:1px solid #666; background-color:#fff; }
#divcontent { height:60px; }
#divbtn { height:40px; background-color:#ddd; text-align:center; }
#btn { border:1px solid #000; margin-top:10px; }
</style>
</head>
<body>
<div style='height:1000px;'>fsfs</div>
</body>
</html>
window.onload = function() {
showDiv();
alert(1);
}