首页 > 代码库 > 友好地弹出对话框
友好地弹出对话框
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 }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。