此方法将散列转换为其 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>Click the button to see the result.</p>
<br />
<br />
<input type = "button" value = "Result" onclick = "showResult();"/>
</body>
</html>作者:terry,如若转载,请注明出处:https://www.web176.com/prototype_api/8711.html
支付宝
微信