<html lang="zh-cn">
<head>
<meta charset="utf-8" />
<title>d出居中动画提示框</title>
<style>
#login{
position: relative;
display: none;
top: 20px;
left: 30px;
background: #fff;
text-align: center;
border: solid 1px;
padding: 10px;
z-index: 1;
position:fixed!important;/FF、IE7/
position:absolute;/IE6/
_top:expression(eval(documentcompatMode &&
documentcompatMode=='CSS1Compat')
documentElementscrollTop + (documentdocumentElementclientHeight-thisoffsetHeight)/2 :
documentbodyscrollTop + (documentbodyclientHeight - thisclientHeight)/2);
}
</style>
<script type="text/javascript">
var W = screenwidth; //取屏幕分辨率宽
var H = screenheight; //取屏幕分辨率高
function M(id){return documentgetElementById(id);} //用M()方法代替documentgetElementById(id)
function MC(t){return documentcreateElement(t);} //用MC()方法代替documentcreateElement(t)
function isIE(){return (documentall && windowActiveXObject && !windowopera) true : false;}//判断浏览器是否为IE
//取得页面的高宽
function getBodySize(){
var bodySize = [];
with(documentdocumentElement){
bodySize[0] = (scrollWidth > clientWidth) scrollWidth : clientWidth; //如滚动条宽大于页面宽,取滚动条宽,否则取页面宽
bodySize[1] = (scrollHeight > clientHeight) scrollHeight : clientHeight; //如滚动条高大于页面高,取滚动条高,否则取页面高
}
return bodySize;
}
//创建遮盖层
function popCoverDiv(){
if (M("cover_div")) {
//如果存在遮盖层,则让其显示
M("cover_div")styledisplay = "block";
}
else {
//否则创建遮盖层
var coverDiv = MC("div");
documentbodyappendChild(coverDiv);
coverDivid = "cover_div";
with(coverDivstyle) {
position = "absolute";
background = "#000";
left = "0px";
top = "0px";
var bodySize = getBodySize();
width = bodySize[0] + "px";
height = bodySize[1] + "px";
zIndex = 0;
//判断是否是ie,并为ie和FF等用不同的方法设置层的半透明
if (isIE()) {filter = "Alpha(Opacity=60)";}
else {opacity = 06;}
}
}
}
//让登陆层显示为块
function showLogin(){
var login=M("login");
loginstyledisplay = "block";
}
//设置login层的样式
function change(){
var login = M("login");
loginstyleposition = "absolute";
loginstyleborder = "1px solid #CCCCCC";
loginstylebackground ="#F6F6F6";
var i = 0;
popChange(i);//调用让DIV层大小循环增大的函数
}
//让DIV层大小循环增大
function popChange(i){
var login = M("login");
var bodySize = getBodySize();
loginstyleleft = (bodySize[0]-ii4)/2+"px";
//loginstyletop = (bodySize[1]/2-100-ii)+"px";
loginstyletop = H/2 + "px";
loginstylemarginTop = -20 + "%";
loginstylewidth = ii4 + "px";
loginstyleheight = ii15+ "px";
if(i<=10){
i++;
setTimeout("popChange("+i+")",10);//设置超时10毫秒
}
}
//打开DIV层
function open(){
change();
showLogin();
popCoverDiv();
void(0);//不进行任何 *** 作,如:<a href="#">aaa</a>
}
//关闭DIV层
function close(){
M("login")styledisplay = "none";
M("cover_div")styledisplay = "none";
void(0);
}
</script>
</head>
<body>
<a href="###" id="openDIV">登陆</a>
<div id="login">
<h1>用户登陆</h1>
自己把里面改成:表单和单选按钮
<a href="###" id="closeDIV">关闭</a>
</div>
<script>
//绑定click打开和关闭d出层事件
function addEvent(obj,type,handle){
try {
objaddEventListener(type,handle,false);// Chrome、FireFox、Opera、Safari、IE9+
}
catch(e) {
try {
objattachEvent('on' + type,handle);// IE80及以下
}
catch(e) {
obj['on' + type] = handle;//更早期浏览器
}
}
}
var openEL = documentgetElementById("openDIV");
var closeEL = documentgetElementById("closeDIV");
addEvent(openEL,"click",open);//监听
addEvent(closeEL,"click",close);
</script>
<p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p>
<p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p>
<p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p>
<p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p>
<p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p>
<p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p>
</body>
</html>
其次,调用JSd出消息;
建议使用jquery框架,
当然还要有html内容:<div id="tankuang_message" style="display:none;">message</div>
当然这个div的样式需要你自己去美化,去定位的,并且要有d窗的效果。
d出时:$('#tankuang_message')show();
关闭时:$('#tankuang_message')hide();
如果你实在不想用,那是可行的,就是麻烦点,还有可能存在兼容性问题。
d出时:documentgetElementById('tankuang_message')styledisplay = '';
d出时:documentgetElementById('tankuang_message')styledisplay = 'none';<script>
function a(){
var xuehao= documentgetElementById("textfield")value;
var name=documentgetElementById("textfield2")value;
alert("你的学号是:"+xuehao+" 你的姓名是"+name);
}
</script>
<input type="submit" name="button" id="button" value="提交" onClick="a()"/> 在提交按钮上加事件
不明白再HI我
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)