模仿easyui dialog的效果 <script> <br>//取得页面元素 <br>var getElement = function() { <br>return document.getElementById(arguments[0]) || false; <br>} <br>function openDialog(dialogId) { <br>var maskId = "mask"; <br>//如果有,先删除原来的 <br>if (getElement(dialogId)) { <br>document.removeChild(getElement(dialogId));//删除操作:弹出的div <br>} <br>if (getElement(maskId)) { <br>document.removeChild(getElement(maskId));//删除操作:弹出的不可操作(面具)层 <br>} <br><br>//背景置灰 <br>var maskDiv = document.createElement("div"); <br>maskDiv.id = maskId; <br>maskDiv.style.position = "absolute"; <br>maskDiv.style.zIndex = "1"; <br>maskDiv.style.width = document.body.scrollWidth "px"; <br>maskDiv.style.height = document.body.scrollHeight "px"; <br>maskDiv.style.top = "0px"; <br>maskDiv.style.left = "0px"; <br>maskDiv.style.background = "gray"; <br>maskDiv.style.filter = "alpha(opacity=10)"; <br>maskDiv.style.opacity = "0.30";//透明度 <br>document.body.appendChild(maskDiv);//向body之中增加背景层 <br><br>//Dialog <br>var dialogDiv = document.createElement("div"); <br>dialogDiv.id = dialogId; <br>dialogDiv.style.position = "absolute"; <br>dialogDiv.style.zIndex = "9999"; <br>dialogDiv.style.width = "400px"; <br>dialogDiv.style.height = "200px"; <br>dialogDiv.style.top = (parseInt(document.body.scrollHeight) - 200) / 2 "px"; // 屏幕居中 <br>dialogDiv.style.left = (parseInt(document.body.scrollWidth) - 400) / 2 "px"; // 屏幕居中 <br>dialogDiv.style.background = "white"; <br>dialogDiv.style.border = "1px solid gray"; <br>dialogDiv.style.padding = "5px"; <br>dialogDiv.innerHTML = "(Dialog Content)"; <br>//Dialog之中的关闭操作:关闭背景层和Dialog层 <br>var closeControlloer = document.createElement("a");//创建一个超链接(做为关闭的触发) <br>closeControlloer.href = "#"; <br>closeControlloer.innerHTML = "关闭"; <br>closeControlloer.onclick = function() { <br>document.body.removeChild(getElement(dialogId));//删除diaglog <br>document.body.removeChild(getElement(maskId));//删除背景层 <br>} <br>dialogDiv.appendChild(closeControlloer);//dialog之中增加"关闭"操作 <br>document.body.appendChild(dialogDiv);//body之中增加dialog <br>} <br></script>
Open Dialog