首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

js处置json

2013-10-22 
js处理json1:生成下接列表htmlheadscriptvar arrayNation [{id:0,devName:billing},{id:1

js处理json
1:生成下接列表

<html><head><script>var arrayNation = [{"id":0,"devName":"billing"},{"id":1,"devName":"log"}];function createSelect(str){var _select = document.createElement("select");var firstOption = document.createElement("option");firstOption.value = "------select------";firstOption.text = "------请选择------";_select.appendChild(firstOption);for ( i = 0; i < str.length; i++){var _option = document.createElement("option");_option.value = str[i].id.toString();_option.text = str[i].devName.toString();_select.appendChild(_option);}return _select;}</script></head><body><div id="dep"/><script>document.getElementById("dep").appendChild(createSelect(arrayNation));</script></body></html>
?2:区分对像与数组
JSON对象:
var str2 = { "name": "cxh", "sex": "man" };?3JSON字符串转换为JSON对象
_option.selected="selected"
?

热点排行