javascript、JQuery運算元組、Json對象、緩衝

來源:互聯網
上載者:User

 

 

1.建立JSON對象

var objJson = [];


 

2.JSON賦值

var objJson = jQuery.parseJSON('[{"PID":1,"Cnt":1}]'); objJson.push(jQuery.parseJSON('{"PID":' + iPID + ',"Cnt":' + iCnt + '}'));


 

3.JSON取值

 

      /**    * json工具    */    var JsonUtil = (function(){    return {        /**         * 擷取json中的單個值         */        getValue:function(jsonObject,name){            var value = "";            $.each(jsonObject,function(n,v){                if(name == n){                    value = v;                    return false;                }            });            return value;        },        /**         * 擷取json中的name 以數組形式返回         */        getNames:function(jsonObject){            var names = [];            $.each(jsonObject,function(n,v){                names.push(n);            });            return names;        },        /**         * 建立json對象         */        createJsonObject:function(){            this.jsonObectArr = [];        }    }    })();  


 

 4.jquery緩衝

 

$("div").data("blah");  // undefined$("div").data("blah", "hello");  // blah設定為hello$("div").data("blah");  // hello$("div").data("blah", 86);  // 設定為86$("div").data("blah");  //  86$("div").removeData("blah");  //移除blah$("div").data("blah");  // undefined$("div").data("test", { first: 16, last: "pizza!" });$("div").data("test").first  //16;$("div").data("test").last  //pizza!;


 

5.數組

var arr = new Array();arr[0]=0;  //賦值arr.push(88); //賦值


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.