下面是個類似QQ網頁登陸的一個對話方塊(DIV), js + json 動態產生:
:
<html><br /><head><br /><mce:script type="text/javascript"><!--<br />LoginWindow = function(jsonObject)<br />{<br />this.width = jsonObject.width;<br />this.height = jsonObject.height;<br />this.titleColor = jsonObject.titleColor;<br />this.backgroundColor = jsonObject.backgroundColor;<br />this.LwHeight = (document.body.clientHeight - this.width) / 2; //讓div在螢幕的中間<br />this.LwWidth = (document.body.clientWidth - this.height) / 2; //讓div在螢幕的中間<br />}<br />LoginWindow.prototype =<br />{<br />createLoginBody: function() //建立登陸框, 即整個框<br />{<br />var loginWindow = document.createElement("div");<br />with(loginWindow.style)<br />{<br />border = "1px solid black";<br />position = "absolute";<br />width = this.width + "px";<br />height = this.height + "px";<br />top = this.LwHeight + "px";<br />left = this.LwWidth + "px";<br />backgroundColor = this.backgroundColor;</p><p>}<br />return loginWindow;<br />},<br />createLoginTitle:function() //建立 標題 即的黑色標題<br />{<br />var title = document.createElement("div");<br />var table = document.createElement("table");<br />var tbody = document.createElement("tbody");<br />var tr = document.createElement("tr");<br />var td_1 = document.createElement("td");<br />var td_2 = document.createElement("td");<br />var close = document.createElement("a");<br />close.onclick = function()<br />{<br />document.body.removeChild(title.parentNode);</p><p>}<br />close.innerHTML = "X";<br />td_1.innerHTML = "welcome";<br />with(title.style)<br />{<br />width = "100%";<br />height = this.height / 8 + "px";<br />backgroundColor = this.titleColor;<br />}<br />with(table.style)<br />{<br />width = "100%";<br />backgroundColor = this.titleColor;<br />color = "white";<br />}<br />td_2.style.textAlign = "right";<br />td_2.appendChild(close);<br />tr.appendChild(td_1);<br />tr.appendChild(td_2);<br />tbody.appendChild(tr);<br />table.appendChild(tbody);<br />title.appendChild(table);<br />return title;</p><p>},<br />loadWindow : function() //組合視窗<br />{<br />var loginWindow = this.createLoginBody();<br />var title = this.createLoginTitle();<br />loginWindow.appendChild(title);<br />document.body.appendChild(loginWindow);</p><p>}</p><p>}</p><p>// --></mce:script><br /></head><br /><body><br /><mce:script type="text/javascript"><!--<br />var go = new LoginWindow({width : "300", height : "200", backgroundColor : "white", titleColor : "black"});<br />go.loadWindow();</p><p>// --></mce:script><br /></body><br /></html>