蛮漂亮的已个JS弹出对话框,之前从网上找来的,再修改过,加上一个参数,可以添加标题。代码也蛮简单的。

功能:弹出对话框,点击标题可关闭对话框。

截图:

image

代码:

JavaScript代码
  1. <script type=“text/javascript” language=“javascript”>
  2. function sAlert(strTitle,strContent){
  3. var msgw,msgh,bordercolor;
  4. msgw=400;//提示窗口的宽度
  5. msgh=100;//提示窗口的高度
  6. titleheight=25 //提示窗口标题高度
  7. bordercolor=“#336699”;//提示窗口的边框颜色
  8. titlecolor=“#99CCFF”;//提示窗口的标题颜色
  9. var sWidth,sHeight;
  10. sWidth=document.body.offsetWidth;
  11. sHeight=screen.height;
  12. var bgObj=document.createElement(“div”);
  13. bgObj.setAttribute(‘id’,‘bgDiv’);
  14. bgObj.style.position=“absolute”;
  15. bgObj.style.top=“0”;
  16. bgObj.style.background=“#777”;
  17. bgObj.style.filter=“progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75”;
  18. bgObj.style.opacity=“0.6”;
  19. bgObj.style.left=“0”;
  20. bgObj.style.width=sWidth + “px”;
  21. bgObj.style.height=sHeight + “px”;
  22. bgObj.style.zIndex = “10000”;
  23. document.body.appendChild(bgObj);
  24. var msgObj=document.createElement(“div”)
  25. msgObj.setAttribute(“id”,“msgDiv”);
  26. msgObj.setAttribute(“align”,“center”);
  27. msgObj.style.background=“white”;
  28. msgObj.style.border=“1px solid “ + bordercolor;
  29. msgObj.style.position = “absolute”;
  30. msgObj.style.left = “50%”;
  31. msgObj.style.top = “50%”;
  32. msgObj.style.font=“12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif”;
  33. msgObj.style.marginLeft = “-225px” ;
  34. msgObj.style.marginTop = -75+document.documentElement.scrollTop+“px”;
  35. msgObj.style.width = msgw + “px”;
  36. msgObj.style.height =msgh + “px”;
  37. msgObj.style.textAlign = “center”;
  38. msgObj.style.lineHeight =“25px”;
  39. msgObj.style.zIndex = “10001”;
  40. var title=document.createElement(“h4”);
  41. title.setAttribute(“id”,“msgTitle”);
  42. title.setAttribute(“align”,“right”);
  43. title.style.margin=“0”;
  44. title.style.padding=“3px”;
  45. title.style.background=bordercolor;
  46. title.style.filter=“progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);”;
  47. title.style.opacity=“0.75”;
  48. title.style.border=“1px solid “ + bordercolor;
  49. title.style.height=“18px”;
  50. title.style.font=“12px Verdana, Geneva, Arial, Helvetica, sans-serif”;
  51. title.style.color=“white”;
  52. title.style.cursor=“pointer”;
  53. title.title = “点击关闭”;
  54. title.innerHTML=“<table border=’0′ width=’100%’><tr><td align=’left’><b>”+ strTitle +“</b></td><td>关闭</td></tr></table></div>”;
  55. title.onclick=function(){
  56. document.body.removeChild(bgObj);
  57. document.getElementById(“msgDiv”).removeChild(title);
  58. document.body.removeChild(msgObj);
  59. }
  60. document.body.appendChild(msgObj);
  61. document.getElementById(“msgDiv”).appendChild(title);
  62. var txt=document.createElement(“p”);
  63. txt.style.margin=“1em 0”
  64. txt.setAttribute(“id”,“msgTxt”);
  65. txt.innerHTML=strContent;
  66. document.getElementById(“msgDiv”).appendChild(txt);
  67. }
  68. </script>

演示:http://www.bokelife.com/demo/alter.htm