前端網頁技術以此HTML、CSS、Javascript為基礎
- HTML to define the content of web pages
- CSS to specify the layout of web pages
- JavaScript to program the behavior of web pages
----JSON to exchange/transfer data, {"key1":"value1", "key2":"value2",.... }
HTML vs XHTML :
HTML的一部份的屬性值沒有屬性值(checked、selected、nowrap、disabled、noresize等屬性),但是XHTML必須要有屬性值,其屬性值和屬性名稱相同。
<input type = "radio" checked = "checked" />
<option value = "F" selected= "selected" >F</option>
2) id屬性取代name屬性
HTML的一部份的元素(a、applet、frame、form、iframe、frame、map、img等元素)可以使用name屬性,但是XHTML1.0不採用name屬性,將由id屬性取代。
JSON
- Data is in name/value pairs : data-->"name":value
- Data is separated by commas: data1, data2,
- Curly braces hold objects : {object}--> { data1, data2, ..}
- Square brackets hold arrays : [{object},{object},...]
This JSON syntax defines an employees object: an array of 3 employee records (objects):
{ --> object
"employees":[ --> Array
{"firstName":"John", "lastName":"Doe"}, ---> {object}
{"firstName":"Anna", "lastName":"Smith"}, ---> {object}
{"firstName":"Peter", "lastName":"Jones"} --->{object}
]
}
-->
Converting a JSON Text to a JavaScript Object
var text = '{ "employees" : [' +'{ "firstName":"John" , "lastName":"Doe" },' +
'{ "firstName":"Anna" , "lastName":"Smith" },' +
'{ "firstName":"Peter" , "lastName":"Jones" } ]}';
Example:
<html>
<body>
<p id="demo"></p>
<script>
var text = '{"employees":[' +
'{"firstName":"John","lastName":"Doe" },' +
'{"firstName":"Anna","lastName":"Smith" },' +
'{"firstName":"Peter","lastName":"Jones" }]}';
obj = JSON.parse(text);
document.getElementById("demo").innerHTML =
obj.employees[2].firstName + " " + obj.employees[1].lastName;
</script>
</body>
</html>
output ==> Peter Smith
沒有留言 :
張貼留言