此方法将散列转换为其 URL 编码的查询字符串表示形式。
这是一种序列化形式,主要用于为 Ajax 名称空间(例如 Ajax.Request)中的对象等内容提供复杂的参数集。
未定义值对将被序列化为空值。数组值对将使用每个数组元素一个名称/值对进行序列化。所有值都使用 JavaScript 的本机 encodeURIComponent 函数进行 URI 编码。
语法
hash.toQueryString();
返回值
返回 URL 编码的查询字符串。
例子
HTML
x
20
20
1
<html>
2
<head>
3
<title>Prototype examples</title>
4
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
5
6
<script>
7
function showResult() {
8
var h = $H({action:'ship',order_id:123,fees: ['f1', 'f2']});
9
alert( "h.toQueryString() : " + h.toQueryString() );
10
}
11
</script>
12
</head>
13
14
<body>
15
<p>Click the button to see the result.</p>
16
<br />
17
<br />
18
<input type = "button" value = "Result" onclick = "showResult();"/>
19
</body>
20
</html>
阅读剩余 33%
作者:terry,如若转载,请注明出处:https://www.web176.com/prototype_api/8711.html