2010-07-20 85 views

回答

1

這裏是source directly from jQueryMIT license):

jQuery.param = function(a, traditional) { 
    var prefix, 
     s = [], 
     add = function(key, value) { 
      // If value is a function, invoke it and return its value 
      value = jQuery.isFunction(value) ? value() : (value == null ? "" : value); 
      s[ s.length ] = encodeURIComponent(key) + "=" + encodeURIComponent(value); 
     }; 

    // Set traditional to true for jQuery <= 1.3.2 behavior. 
    if (traditional === undefined) { 
     traditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional; 
    } 

    // If an array was passed in, assume that it is an array of form elements. 
    if (jQuery.isArray(a) || (a.jquery && !jQuery.isPlainObject(a))) { 
     // Serialize the form elements 
     jQuery.each(a, function() { 
      add(this.name, this.value); 
     }); 

    } else { 
     // If traditional, encode the "old" way (the way 1.3.2 or older 
     // did it), otherwise encode params recursively. 
     for (prefix in a) { 
      buildParams(prefix, a[ prefix ], traditional, add); 
     } 
    } 

    // Return the resulting serialization 
    return s.join("&").replace(r20, "+"); 
}; 
+1

歡迎堆棧溢出!不鼓勵使用僅有代碼的答案。你可以編輯你的帖子來描述你的代碼在哪裏嗎? – 2015-04-29 13:32:47

+1

這可能是一個正確的答案,但是,缺乏一個來源意味着1)沒有提供上下文,並且2)非常容易過時。一個鏈接和一個小解釋將改善這個答案很多 – Chubas 2015-04-29 15:58:36

+0

請解釋你在未來從何處獲得源代碼,只需將代碼粘貼到此處並聲明它爲你自己的代碼就是違反jQuery許可證。我添加了適當的屬性。 – 2015-04-29 16:29:37

相關問題