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