JSON Reference Application
JSON (JavaScript Object Notation) is a lightweight data interchange format. JSON takes a completely language-independent text format, which makes JSON an ideal data exchange language. Easy to read and write, but also easy to machine parse and generate.
The following is a simple pop-up widget that changes the style of the pop-up window by using JSON parameters.
Html:
< button id = "Open" > open </ button > < button id = "Close" > close </ button > < div id = "box" ></ div >
Js:
functionAlert (JSON) { This. Win=document.getelementbyid (' box '); This. w=json.width| | 200; //If the parameter is ' ', it is displayed. This. h=json.height| | 150; This. content=json.content| | ' Box; This. win.style.height= This. H + ' px '; This. win.style.width= This. w+ ' px '; This. win.innertext= This. Content; This. win.style.background=json.background| | ' Black; This. win.style.color=json.color| | ' White; } Alert.prototype.open=function() {// object prototype, open on Close close This. win.style.display= ' Block '; } Alert.prototype.close=function(){ This. win.style.display= ' None '; }
Call JS:
Window.onload=function(){ varOpen=document.getelementbyid (' Open '); varClose=document.getelementbyid (' Close '); varbox=NewAlert ({height:100, Width:100, Content:' Pop the window ', background:' Red ', Color:' Blue ' }); Open.onclick=function() {box.open (); }; Close.onclick=function() {Box.close ()}};
JSON Reference Application