How to code a JavaScript modal popup (to replace Ajax)?

后端 未结 4 558
傲寒
傲寒 2020-11-27 17:27

I need to replace our Ajax Modal Popup controls with a JavaScript equivalent. We use this as a simple context sensitive help type popup. I did a quick browse but didn\'t see

4条回答
  •  自闭症患者
    2020-11-27 17:43

    I can provide you the code. Do your modifications as necessary, OK?

    Page JavaScript:

    function myPop() { 
        this.square = null;
        this.overdiv = null;
    
        this.popOut = function(msgtxt) {
            //filter:alpha(opacity=25);-moz-opacity:.25;opacity:.25;
            this.overdiv = document.createElement("div");
            this.overdiv.className = "overdiv";
    
            this.square = document.createElement("div");
            this.square.className = "square";
            this.square.Code = this;
            var msg = document.createElement("div");
            msg.className = "msg";
            msg.innerHTML = msgtxt;
            this.square.appendChild(msg);
            var closebtn = document.createElement("button");
            closebtn.onclick = function() {
                this.parentNode.Code.popIn();
            }
            closebtn.innerHTML = "Close";
            this.square.appendChild(closebtn);
    
            document.body.appendChild(this.overdiv);
            document.body.appendChild(this.square);
        }
        this.popIn = function() {
            if (this.square != null) {
                document.body.removeChild(this.square);
                this.square = null;
            }
            if (this.overdiv != null) {
            document.body.removeChild(this.overdiv);
            this.overdiv = null;
            }
    
        }
    }
    

    Now the HTML page, using the JavaScript file:

     
      
        
        
      
      
        

    Hope that this can help.

提交回复
热议问题