jquery param()

來源:互聯網
上載者:User

標籤:jquery

jQuery.param()函數用於將一個JS數組或對象序列化為字串值,將jquery對象按照name/value 或者key/value序列化為URL參數,用&串連。以便用於URL查詢字串或AJAX請求。


文法


$.param(object,trad)


參數說明


object:必需。規定要序列化的數組或對象。

trad:可選。布爾值,指定是否使用參數序列化的傳統樣式。

 

執行個體

 

var v1 = $.param( true ); // ""var v2 = $.param( 100 ); // ""var v3 = $.param( 12.34 ); // ""var v4 = $.param( "" ); // ""var v5 = $.param( function(){ return 18; } ); // ""var v6 = $.param( /\\d+/ ); // ""var v7 = $.param( new Date() ); // ""var v8 = $.param( null ); // 報錯var v9 = $.param( undefined ); // 報錯// 字串將被看作一個字元數組var v10 = $.param( "name" ); // "0=n&1=a&2=m&3=e"var v11 = $.param({ name:"CodePlayer", age:18 } ); // "name=CodePlayer&age=18"var array = [    { name: "name", value: "張三" },    { name: "age", value: 18, extra: "忽略該屬性" },    { name: "grade" }, // 沒有value屬性,則value值為undefined,將被轉為空白字串""    { name: "orderId", value: 2 },    { name: "orderId", value: 3 },];var v12 = $.param( array ); // "name=%E5%BC%A0%E4%B8%89&age=18&grade=&orderId=2&orderId=3"// jQuery將數組的每個元素視作對象,並調用其name和value屬性// 由於這些元素沒有name屬性,所以為undefined,並被轉為字串"undefined"// 由於這些元素沒有value屬性,所以為undefined,並被轉為空白字串""var v13 = $.param( [ "name", 2, 3 ] ); // "undefined=&undefined=&undefined="



參考資料: jquery param方法   http://www.studyofnet.com/news/933.html

本文出自 “學習也休閑” 部落格,請務必保留此出處http://studyofnet.blog.51cto.com/8142094/1695967

jquery param()

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.