一个通过的网页模式对话框

时间: 2010-01-26 / 分类: Javascript / 浏览次数: 11 views / 0个评论 发表评论

说明:
msg:对话框显示的消息
callbackOK:正确时调用的函数
callbackCancel: 取消时调用的函数
dom:绑定的DOM元素


          var iMessageBox = function(msg, callbackOk, callbackCancel, dom){
            var mask = document.createElement('div');
            var pop = document.createElement('div');
            var message = document.createElement('h4');
            var ok = document.createElement('input');
            ok.type = "button";
            ok.value = "__MSG_ok__";
            ok.__dom = dom;
            ok.__func = callbackOk;
            ok.__mask = mask;
            ok.__pop = pop;
            ok.onclick = function(){
              if(this.__func)
                this.__func.call(this.__dom);
              document.body.removeChild(this.__mask);
              document.body.removeChild(this.__pop);
            }
            message.innerHTML = msg;
            var cancel = document.createElement('input');
            cancel.type = "button";
            cancel.value = '__MSG_cancel__';
            cancel.__dom = dom;
            cancel.__mask = mask;
            cancel.__pop = pop;
            cancel.__func = callbackCancel;
            cancel.onclick = function(){
              if(this.__func)
                this.__func.call(this.__dom);
              document.body.removeChild(this.__mask);
              document.body.removeChild(this.__pop);
            }
            pop.appendChild(message);
            pop.appendChild(ok);
            pop.appendChild(cancel);
            document.body.appendChild(mask);
            document.body.appendChild(pop);
            mask.style.cssText = 'position:absolute;background:#000;opacity:.3;width:100%;*filter: Alpha(Opacity=30);top:0;left:0';
            mask.style.display = 'block';
            mask.style.height = document.body.clientHeight +document.body.scrollTop+ 'px';
            document.body.style.overflow = 'hidden';
            pop.style.cssText = 'position:absolute;width:200;padding:8px;background:#fff;border:2px solid #000;text-align:center';
            pop.style.display = 'block';
            pop.style.left =document.body.offsetWidth / 2 - pop.offsetWidth / 2 + 'px';
            pop.style.top = document.body.offsetHeight / 2 - pop.offsetHeight / 2 + 'px';
          }

发表评论

您的昵称 *

您的邮箱 *

您的网站