本文實例講述了jQuery實現簡單復制json對象和json對象集合操作。分享給大家供大家參考,具體如下:
<!DOCTYPE html><html><head> <meta name="viewport" content="width=device-width" /> <title>www.companysz.com jQuery復制json</title> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <script type="text/javascript"> $(function () { var classList = [ { classId: 1, className: '一班', students: [ { studentId: 1, studentName: '張三' }, { studentId: 2, studentName: '李四' } ] }, { classId: 2, className: '二班', students: [ { studentId: 3, studentName: '王五' }, { studentId: 4, studentName: '馬六' } ] } ] var classDemo = { classId: 1, className: '一班', students: [ { studentId: 1, studentName: '張三' }, { studentId: 2, studentName: '李四' } ] } var newClassList = jQuery.extend(true, [], classList);//復制對象集合 var newClassDemo = jQuery.extend(true, {}, classDemo);//復制對象 //輸出測試: console.log(newClassList); console.log(newClassDemo); }); </script></head><body></body></html>
使用本站HTML/CSS/JS在線運行測試工具:http://tools.VeVB.COm/code/HtmlJsRun,可得到如下測試運行效果:
PS:關于json操作,這里再為大家推薦幾款比較實用的json在線工具供大家參考使用:
在線JSON代碼檢驗、檢驗、美化、格式化工具:
http://tools.VeVB.COm/code/json
JSON在線格式化工具:
http://tools.VeVB.COm/code/jsonformat
在線XML/JSON互相轉換工具:
http://tools.VeVB.COm/code/xmljson
json代碼在線格式化/美化/壓縮/編輯/轉換工具:
http://tools.VeVB.COm/code/jsoncodeformat
在線json壓縮/轉義工具:
http://tools.VeVB.COm/code/json_yasuo_trans
更多關于jQuery相關內容感興趣的讀者可查看本站專題:《jQuery操作json數據技巧匯總》、《jQuery常用插件及用法總結》、《jQuery擴展技巧總結》及《jquery選擇器用法總結》
希望本文所述對大家jQuery程序設計有所幫助。
新聞熱點
疑難解答