程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> html5+-關於JS的類型問題!!!

html5+-關於JS的類型問題!!!

編輯:編程綜合問答
關於JS的類型問題!!!

var testStr = '[{"aa":"a1","bb":"b1","cc":"c1","dd":"d1"},{"aa":"a2","bb":"b2","cc":"c2","dd":"d2"},{"aa":"a3","bb":"b3","cc":"c3","dd":"d3"},{"aa":"a4","bb":"b4","cc":"c4","dd":"d4"},{"aa":"a5","bb":"b5","cc":"c5","dd":"d5"}]';

這個testStr是什麼類型?如何給它添加新的內容?

補充:這樣this.objectlist = eval('('+testStr+')');,有什麼用哦?eval後得到的什麼?

最佳回答:


這是json格式的字符串
 <!DOCTYPE html>
<html>
<body>
<script>
var testStr = '[{"aa":"a1","bb":"b1","cc":"c1","dd":"d1"},{"aa":"a2","bb":"b2","cc":"c2","dd":"d2"},{"aa":"a3","bb":"b3","cc":"c3","dd":"d3"},{"aa":"a4","bb":"b4","cc":"c4","dd":"d4"},{"aa":"a5","bb":"b5","cc":"c5","dd":"d5"}]';
var jsontext = eval('('+testStr+')');
for(var i=0;i<jsontext.length;i++){
   document.write(jsontext[i].aa+',');
   jsontext[i]['添加內容']='cccc';
   document.write(jsontext[i].添加內容+',');
}
</script>

</body>
</html>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved