码迷,mamicode.com
首页 > 其他好文 > 详细

友好地弹出对话框

时间:2014-08-11 09:55:41      阅读:273      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   java   os   io   ar   cti   

 1 function showMessage(msg, bgColor, borderColor) {
 2     if ($("#showDiv").length <= 0) {
 3         var div = window.document.createElement("div");
 4         div.innerHTML = msg;
 5         div.id = "showDiv";
 6         div.style.color = "black";
 7         div.style.width = "400px";
 8         div.style.height = "auto";
 9         div.style.padding = "15px";
10         div.style.lineHeight = "22px";
11         div.style.overflow = "auto";
12         div.style.border = borderColor;
13         div.style.display = "none";
14         div.style.position = "fixed";
15         div.style.zIndex = 40;
16         div.style.fontFamily = "Microsoft YaHei";
17         div.style.fontSize = "15px";
18 
19         div.style.background = bgColor;
20         var p = window.document.createElement("p");
21         p.style.marginBottom = "0px";
22         p.style.textAlign = "right";
23 
24         $(p).html("<a id=‘closeA‘ href=‘javascript:void(0)‘ style=‘text-decoration:none‘>关闭</a>");
25         div.appendChild(p);
26         window.document.body.appendChild(div);
27 
28         div.style.left = (window.document.documentElement.clientWidth / 2 - parseInt(div.style.width, 10) / 2) + "px";
29         div.style.top = window.document.documentElement.clientHeight / 2 - $(div).height() / 2 + "px";
30         animationDiv(div);
31 
32         //这里要放在元素被body加载了后再绑定事件,不然放在加载之前执行不了事件
33         $("#closeA").click(function () {
34             $("#showDiv").remove();
35         });
36 
37         $(window).resize(function () {
38             div.style.left = (window.document.documentElement.clientWidth / 2 - parseInt(div.style.width, 10) / 2) + "px";
39             div.style.top = window.document.documentElement.clientHeight / 2 - $(div).height() / 2 + "px";
40         });
41 
42     } else {
43         //$("#showDiv").html(msg + "<p style=‘text-align:right‘><a id=‘closeA‘ href=‘javascript:void(0)‘ style=‘text-decoration:none‘>关闭</a></p>");
44         //这里要放在元素被body加载了后再绑定事件,不然放在加载之前执行不了事件
45         $("#closeA").click(function () {
46             $("#showDiv").remove();
47         });
48     }
49 }

 

友好地弹出对话框,布布扣,bubuko.com

友好地弹出对话框

标签:style   blog   color   java   os   io   ar   cti   

原文地址:http://www.cnblogs.com/aspnetweb/p/3904011.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!