深入javascript –> json

來源:互聯網
上載者:User

 

 

下面是個類似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>

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.