javascript onclick create(element) div viz popup box

前端 未结 4 1087
天涯浪人
天涯浪人 2021-01-15 01:51

I\'m trying to make a pop up box, which gets invoked on clicking a button, this is what I\'ve got so far.. http://jsfiddle.net/WGPhG/2/

4条回答
  •  悲哀的现实
    2021-01-15 02:08

    I've updated your Fiddle and made it work.

    The changed HTML...

     
    

    Updated JavaScript...

    document.onreadystatechange = function () {
        function popUp() {
            var popup = document.createElement('div');
            popup.className = 'popup';
            popup.id = 'test';
    
            popup.innerHTML = "This is a test message";
            
            var cancel = document.createElement('div');
            cancel.className = 'cancel';
            cancel.onclick= function () { popup.destroy(); }
            popup.appendChild(cancel);
            
            document.body.appendChild(popup);
        }
        
        document.getElementById('popupButton').onclick = popUp;
    }​
    

    Did this answer your question or is there anything else?

    Update Improved the code and the fiddle. Now open and close works

提交回复
热议问题