在页面浮一个层出来,并锁定下面的内容不可选。
JS文件
调用JS的方法
还有CSS
JS文件
- function NeatDialog(sHTML, sTitle, bCancel) {
- window.neatDialog = null;
- this.elt = null;
- if (document.createElement && document.getElementById) {
- var dg = document.createElement("div");
- dg.className = "neat-dialog";
- if (sTitle) {
- sHTML = "<div class=/"neat-dialog-title/">" + sTitle + (bCancel ? "<img src=/"x.gif/" alt=/"Cancel/" class=/"nd-cancel/" />" : "") + "</div>/n" + sHTML;
- }
- dg.innerHTML = sHTML;
- var dbg = document.createElement("div");
- dbg.id = "nd-bdg";
- dbg.className = "neat-dialog-bg";
- var dgc = document.createElement("div");
- dgc.className = "neat-dialog-cont";
- dgc.appendChild(dbg);
- dgc.appendChild(dg);
- if (document.body.offsetLeft > 0) {
- dgc.style.marginLeft = document.body.offsetLeft + "px";
- }
- document.body.appendChild(dgc);
- if (bCancel) {
- document.getElementById("nd-cancel").onclick = function () {window.neatDialog.close();};
- }
- this.elt = dgc;
- window.neatDialog = this;
- }
- }
调用JS的方法
- function openDialog()
- {
- var sHTML = '<p>Are you sure you want to destroy the world?</p>'+
- '<p><button οnclick="window.neatDialog.close()">YES!</button></p>';
- new NeatDialog(sHTML, "NeatDialog!", false);
- }
还有CSS
- div.neat-dialog-cont {
- background:transparent none repeat scroll 0%;
- height:100%;
- left:0pt;
- position:absolute;
- top:0pt;
- width:100%;
- z-index:98;
- }
- div.neat-dialog-bg {
- background-color:#EEEEEE;
- height:100%;
- left:0pt;
- opacity:0.7;
- position:absolute;
- top:0pt;
- width:100%;
- z-index:-1;
- }
- div.neat-dialog {
- background-color:#FFFFFF;
- border:1px solid #444444;
- margin-left:auto;
- margin-right:auto;
- position:relative;
- top:25%;
- width:30%;
- z-index:99;
- }
- div.neat-dialog-title {
- border-bottom:1px solid #444444;
- font-size:0.8em;
- line-height:1.2em;
- margin:0pt;
- padding:0.1em 0.3em;
- position:relative;
- }