以下通过Jquery实现的弹出框,操作时在同一个页面中,不会弹出新页面,对于操作非Ajax应用的静态数据,如表单填写等较为方便,对于要使用Ajax等实现的可以使用jquery UI组件提供的各种效果,也可以使用一个叫做jquery.cluetip.js的插件实现。
<html>
<head>
<title>测试</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.divbox.js"></script>
<style>
#divSCA
{
position: absolute;
width: 350px;
height: 100px;
font-size: 10px;
background: #fff;
border: 2px solid #7FBFFF;
z-index: 10001;
display: none;
}
#topBar
{
width:100%;
height:12%;
background: #7FBFFF;
margin-top:0px;
position:absolute;
text-align:right;
}
#topBar span
{
float:right;
margin-right:5px;
margin-top:2px;
position: relative;
cursor:hand;
font-size:14px;
}
#select
{
margin-top:30px;
margin-left:10px;
margin-right:10px;
background:#CCFFFF;
}
.content
{
background:#CCFFFF;
width:auto;
font-style:normal;
font-family: System ;
font-size:13px;
}
</style>
<script type="text/javascript">
function openDiv() {
$("#divSCA").OpenDiv();
}
function closeDiv() {
$("#divSCA").CloseDiv();
}
</script>
</head>
<body>
<div id="divSCA">
<p><div id="topBar"><span onClick="closeDiv()">关闭</span></div></p>
<p><div id="select">
<table class="content" border="1" bordercolor="#7F9FAA" cellpadding="5" cellspacing="0">
<tr>
<td colspan="2"><b>会议审核-退回给申请人</b></td>
</tr>
<tr>
<td><input type="radio" value="ttt" name="model" checked="checked"></td>
<td><font color="blue">打回修改后再审核:</font>要求申请人修改后返回到此处开始继续审核</td>
</tr>
<tr>
<td><input type="radio" value="ttt" name="model"></td>
<td><font color="blue">打回修改后重走审核:</font>要求申请人修改后该会议重新开始审核</td>
</tr>
<tr>
<td align="center" colspan="2"><input type="button" value="确 定" onClick=ok()"/>
<input type="button" value="返 回" onClick="closeDiv()"/></td>
</tr>
</table>
</div></p>
</div>
<input type="button" value="弹出" onClick="openDiv()"/>
</body>
</html>
其中jquery.divbox.js源码如下:
//By Robin_TYUT 2010/08/19
//Thank U 4 sharing!
jQuery.fn.extend(
{
OpenDiv: function()
{
var sWidth, sHeight;
sWidth = window.screen.availWidth;
if (window.screen.availHeight > document.body.scrollHeight)
{
sHeight = window.screen.availHeight;
} else
{
sHeight = document.body.scrollHeight + 20;
}
var maskObj = document.createElement("div");
maskObj.setAttribute('id', 'BigDiv');
maskObj.style.position = "absolute";
maskObj.style.top = "0";
maskObj.style.left = "0";
maskObj.style.background = "#111";
maskObj.style.filter = "Alpha(opacity=70);";
maskObj.style.opacity = "0.7";
maskObj.style.width = sWidth + "px";
maskObj.style.height = sHeight + "px";
maskObj.style.zIndex = "10000";
$("body").attr("scroll", "no");
document.body.appendChild(maskObj);
$("#BigDiv").data("divbox_selectlist", $("select:visible"));
$("select:visible").hide();
$("#BigDiv").attr("divbox_scrolltop", $.ScrollPosition().Top);
$("#BigDiv").attr("divbox_scrollleft", $.ScrollPosition().Left);
$("#BigDiv").attr("htmloverflow", $("html").css("overflow"));
$("html").css("overflow", "hidden");
window.scrollTo($("#BigDiv").attr("divbox_scrollleft"), $("#BigDiv").attr("divbox_scrolltop"));
var MyDiv_w = this.width();
var MyDiv_h = this.height();
MyDiv_w = parseInt(MyDiv_w);
MyDiv_h = parseInt(MyDiv_h);
var width = $.PageSize().Width;
var height = $.PageSize().Height;
var left = $.ScrollPosition().Left;
var top = $.ScrollPosition().Top;
var Div_topposition = top + (height / 2) - (MyDiv_h / 2);
var Div_leftposition = left + (width / 2) - (MyDiv_w / 2);
this.css("position", "absolute");
this.css("z-index", "10001");
this.css("background", "#fff");
this.css("left", Div_leftposition + "px");
this.css("top", Div_topposition + "px");
if ($.browser.mozilla)
{
this.show();
return;
}
this.fadeIn("fast");
}
, CloseDiv: function()
{
if ($.browser.mozilla)
{
this.hide();
} else
{
this.fadeOut("fast");
} $("html").css("overflow", $("#BigDiv").attr("htmloverflow"));
window.scrollTo($("#BigDiv").attr("divbox_scrollleft"), $("#BigDiv").attr("divbox_scrolltop"));
$("#BigDiv").data("divbox_selectlist").show();
$("#BigDiv").remove();
}
});
$.extend(
{
PageSize:function ()
{
var width=0;
var height=0;
width=window.innerWidth!=null?window.innerWidth:document.documentElement&&document.documentElement.clientWidth?document.documentElement.clientWidth:document.body!=null?document.body.clientWidth:null;
height=window.innerHeight!=null?window.innerHeight:document.documentElement&&document.documentElement.clientHeight?document.documentElement.clientHeight:document.body!=null?document.body.clientHeight:null;
return {Width:width,Height:height};
}
,ScrollPosition:function ()
{
var top=0,left=0;
if($.browser.mozilla)
{
top=window.pageYOffset;
left=window.pageXOffset;
}
else if($.browser.msie)
{
top=document.documentElement.scrollTop;
left=document.documentElement.scrollLeft;
}
else if(document.body)
{
top=document.body.scrollTop;
left=document.body.scrollLeft;
}
return {Top:top,Left:left};
}
});