javascripot div登陆提示框(页面层不可用)

来源:互联网 发布:python移动图片文件 编辑:程序博客网 时间:2024/05/08 11:40
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  4. <title>greencss.com</title>
  5. <script type="text/javascript">
  6. function sAlert(str,stitle){
  7. var msgw,msgh,bordercolor;
  8. msgw=300;//提示窗口的宽度
  9. msgh=100;//提示窗口的高度
  10. titleheight=25 //提示窗口标题高度
  11. bordercolor="#336699";//提示窗口的边框颜色
  12. titlecolor="#99CCFF";//提示窗口的标题颜色
  13. var sWidth,sHeight;
  14. sWidth=document.body.offsetWidth;//浏览器工作区域内页面宽度
  15. sHeight=screen.height;//屏幕高度(垂直分辨率)
  16. //背景层(大小与窗口有效区域相同,即当弹出对话框时,背景显示为放射状透明灰色)
  17. var bgObj=document.createElement("div");//创建一个div对象(背景层)
  18. //定义div属性,即相当于
  19. //<div id="bgDiv" style="position:absolute; top:0; background-color:#777; filter:progid:DXImagesTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75); opacity:0.6; left:0; width:918px; height:768px; z-index:10000;"></div>
  20. bgObj.setAttribute('id','bgDiv');
  21. bgObj.style.position="absolute";
  22. bgObj.style.top="0";
  23. bgObj.style.background="#777";
  24. bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=2,opacity=25,finishOpacity=75";
  25. bgObj.style.opacity="0.6";
  26. bgObj.style.left="0";
  27. bgObj.style.width=sWidth + "px";
  28. bgObj.style.height=sHeight*2 + "px";
  29. bgObj.style.zIndex = "10000";
  30. document.body.appendChild(bgObj);//在body内添加该div对象
  31. var msgObj=document.createElement("div")//创建一个div对象(提示框层)
  32. //定义div属性,即相当于
  33. //<div id="msgDiv" align="center" style="background-color:white; border:1px solid #336699; position:absolute; left:50%; top:50%; font:12px/1.6em Verdana,Geneva,Arial,Helvetica,sans-serif; margin-left:-225px; margin-top:npx; width:400px; height:100px; text-align:center; line-height:25px; z-index:100001;"></div>
  34. msgObj.setAttribute("id","msgDiv");
  35. msgObj.setAttribute("align","center");
  36. msgObj.style.background="white";
  37. msgObj.style.border="1px solid " + bordercolor;
  38. msgObj.style.position = "absolute";
  39. msgObj.style.left = "50%";
  40. msgObj.style.top = "20%";
  41. msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
  42. msgObj.style.marginLeft = "-225px" ;
  43. msgObj.style.marginTop = -75+document.documentElement.scrollTop+"px";
  44. msgObj.style.width = msgw + "px";
  45. msgObj.style.height =msgh + "px";
  46. msgObj.style.textAlign = "center";
  47. msgObj.style.lineHeight ="25px";
  48. msgObj.style.zIndex = "10001";
  49. var title=document.createElement("h4");//创建一个h4对象(提示框标题栏)
  50. //定义h4的属性,即相当于
  51. //<h4 id="msgTitle" align="right" style="margin:0; padding:3px; background-color:#336699; filter:progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100); opacity:0.75; border:1px solid #336699; height:18px; font:12px Verdana,Geneva,Arial,Helvetica,sans-serif; color:white; cursor:pointer;" onclick="">关闭</h4>
  52. title.setAttribute("id","msgTitle");
  53. title.setAttribute("align","right");
  54. title.style.margin="0";
  55. title.style.padding="3px";
  56. title.style.background=bordercolor;
  57. title.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);";
  58. title.style.opacity="0.75";
  59. title.style.border="1px solid " + bordercolor;
  60. title.style.height="18px";
  61. title.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif";
  62. title.style.color="white";
  63. title.style.cursor="pointer";
  64. title.innerHTML="关闭";
  65. title.onclick=removeObj;
  66. var button=document.createElement("input");//创建一个input对象(提示框按钮)
  67. //定义input的属性,即相当于
  68. //<input type="button" align="center" style="width:100px; align:center; margin-left:250px; margin-bottom:10px;" value="关闭">
  69. button.setAttribute("type","button");
  70. button.setAttribute("value","关闭");
  71. button.style.width="60px";
  72. button.style.align="center";
  73. button.style.marginLeft="250px";
  74. button.style.marginBottom="10px";
  75. button.style.background=bordercolor;
  76. button.style.border="1px solid "+ bordercolor;
  77. button.style.color="white";
  78. button.onclick=removeObj;
  79. function removeObj(){//点击标题栏触发的事件
  80. document.body.removeChild(bgObj);//删除背景层Div
  81. document.getElementById("msgDiv").removeChild(title);//删除提示框的标题栏
  82. document.body.removeChild(msgObj);//删除提示框层
  83. }
  84. document.body.appendChild(msgObj);//在body内添加提示框div对象msgObj
  85. document.getElementById("msgDiv").appendChild(title);//在提示框div中添加标题栏对象title
  86. var txt=document.createElement("p");//创建一个p对象(提示框提示信息)
  87. //定义p的属性,即相当于
  88. //<p style="margin:1em 0;" id="msgTxt">测试效果</p>
  89. txt.style.margin="1em 0"
  90. txt.setAttribute("id","msgTxt");
  91. txt.innerHTML="<a href=http://www.myziy.com><img border=0 src="+str+"></img></a>";//来源于函数调用时的参数值
  92. document.getElementById("msgDiv").appendChild(txt);//在提示框div中添加提示信息对象txt
  93. document.getElementById("msgDiv").appendChild(button);//在提示框div中添加按钮对象button
  94. }
  95. </script>
  96. </head>
  97. <body>
  98. <p style="cursor:hand;" onclick="sAlert('logo.png','登录');">登陆</p>
  99. </body>
  100. </html>
原创粉丝点击