ドキュメント

Utilities/jQuery.param

From jQuery JavaScript Library

Jump to: navigation, search

« Back to Utilities

jQuery.param( obj )

Serializes an array of form elements or an object (core of .serialize() method).
Space characters are encoded as '+' rather than the '%20' produced by Javascript's native encodeURIComponent. This is more compact, but requires caution when parsing a $.param-formatted string in script, since decodeURIComponent doesn't understand '+'.
Arguments:
objArray<Elements>, jQuery, Object
An Array or jQuery object is serialized by name/value pairs. An object by key/value pairs (As of jQuery 1.3, the return value of functions will be used instead of the function as a String).
Examples:

Serialize a key/value object.

    var params = { width:1680, height:1050 };
    var str = jQuery.param(params);
    $("#results").text(str);

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
  
  <script>
  $(document).ready(function(){
    
    var params = { width:1680, height:1050 };
    var str = jQuery.param(params);
    $("#results").text(str);

  });
  </script>
  <style>div { color:red; }</style>
</head>
<body>
  <div id="results"></div>
</body>
</html>

NameType