jQuery實現(xiàn)簡單復制json對象和json對象集合操作示例
本文實例講述了jQuery實現(xiàn)簡單復制json對象和json對象集合操作。分享給大家供大家參考,具體如下:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>m.fzitv.net 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.jb51.net/code/HtmlJsRun,可得到如下測試運行效果:

PS:關于json操作,這里再為大家推薦幾款比較實用的json在線工具供大家參考使用:
在線JSON代碼檢驗、檢驗、美化、格式化工具:
http://tools.jb51.net/code/json
JSON在線格式化工具:
http://tools.jb51.net/code/jsonformat
在線XML/JSON互相轉換工具:
http://tools.jb51.net/code/xmljson
json代碼在線格式化/美化/壓縮/編輯/轉換工具:
http://tools.jb51.net/code/jsoncodeformat
在線json壓縮/轉義工具:
http://tools.jb51.net/code/json_yasuo_trans
更多關于jQuery相關內容感興趣的讀者可查看本站專題:《jQuery操作json數(shù)據(jù)技巧匯總》、《jQuery常用插件及用法總結》、《jQuery擴展技巧總結》及《jquery選擇器用法總結》
希望本文所述對大家jQuery程序設計有所幫助。
相關文章
IE中jquery.form中ajax提交沒反應解決方法分享
用jquery form插件,進行ajax提交,本來可以用,好好地,突然發(fā)現(xiàn),firefox,opera等可以提交,ie的success函數(shù)運行了2012-09-09
jq stop()和:is(:animated)的用法及區(qū)別(詳解)
下面小編就為大家?guī)硪黄猨q stop()和:is(:animated)的用法及區(qū)別(詳解)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-02-02

