此方法解析类似 URI 的查询字符串并返回由参数/值对组成的对象。此方法类似于 parseQuery()。
此方法真正针对解析查询字符串(因此分隔符参数的默认值为“&”)。
语法
string.toQueryParams ([separator = '&']);
返回值
返回具有键值对的对象。
例子
HTML
x
26
26
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 str = "http://www.example.com?section=blog&id=45#comments";
9
var obj = str.toQueryParams ();
10
alert ( "obj.section : " + obj.section );
11
alert ( "obj.id : " + obj.id );
12
13
var str = "tag=ruby%20on%20rails";
14
var obj = str.toQueryParams ();
15
alert ( "obj.tag: " + obj.tag );
16
}
17
</script>
18
</head>
19
20
<body>
21
<p>Click the button to see the result.</p>
22
<br />
23
<br />
24
<input type = "button" value = "Result" onclick = "showResult();"/>
25
</body>
26
</html>
阅读剩余 41%
作者:terry,如若转载,请注明出处:https://www.web176.com/prototype_api/8816.html