Prototype - Hash toQueryString() 方法
此方法将哈希转换为其 URL 编码的查询字符串表示形式。
这是一种序列化形式,主要用于为 Ajax 命名空间中的对象(例如 Ajax.Request)等内容提供复杂的参数集。
未定义值对将被视为空值进行序列化。数组值对将以每个数组元素一个名称/值对的方式进行序列化。所有值都使用 JavaScript 的原生 encodeURIComponent 函数进行 URI 编码。
语法
hash.toQueryString();
返回值
返回 URL 编码的查询字符串。
示例
<html> <head> <title>Prototype examples</title> <script type = "text/javascript" src = "/javascript/prototype.js"></script> <script> function showResult() { var h = $H({action:'ship',order_id:123,fees: ['f1', 'f2']}); alert( "h.toQueryString() : " + h.toQueryString() ); } </script> </head> <body> <p>单击按钮查看结果。</p> <br /> <br /> <input type = "button" value = "Result" onclick = "showResult();"/> </body> </html>
输出
prototype_hash_processing.html