<script type="text/javascript">
<!-- To load a movie other then the first one listed in the xml file you can specify a movie=# arguement. -->
<!-- For example, to load the third movie you would do the following: MyProjectName.html?movie=3 -->
// <![CDATA[
var args = new Object();
var query = location.search.substring(1);
// Get query string
var pairs = query.split( "," );
// Break at comma
for ( var i = 0; i < pairs.length; i++ )
{
var pos = pairs[i].indexOf('=');
if( pos == -1 )
{
continue; // Look for "name=value"
}
var argname = pairs[i].substring( 0, pos ); // If not found, skip
var value = pairs[i].substring( pos + 1 ); // Extract the name
args[argname] = unescape( value ); // Extract the value
}
// ]]>
</script>
就是红字地方 参数不是用&隔开的吗 这里为什么要用split ,
<!-- To load a movie other then the first one listed in the xml file you can specify a movie=# arguement. -->
<!-- For example, to load the third movie you would do the following: MyProjectName.html?movie=3 -->
// <![CDATA[
var args = new Object();
var query = location.search.substring(1);
// Get query string
var pairs = query.split( "," );
// Break at comma
for ( var i = 0; i < pairs.length; i++ )
{
var pos = pairs[i].indexOf('=');
if( pos == -1 )
{
continue; // Look for "name=value"
}
var argname = pairs[i].substring( 0, pos ); // If not found, skip
var value = pairs[i].substring( pos + 1 ); // Extract the name
args[argname] = unescape( value ); // Extract the value
}
// ]]>
</script>
就是红字地方 参数不是用&隔开的吗 这里为什么要用split ,
maybez这个意思
如下所示:var query='h,e,l,l,o';
var pairs = query.split( "," );
for(var i=0;i<pairs.length<;i++) {
alert(pairs[i]);
}
var pairs = query.split( "," );
for(var i=0;i<pairs.length<;i++) {
alert(pairs[i]);
}
参数在url中的确是以&分开的,如html?a=3&b=4&c=5
但location.search.substring(1); 得到的将是search包含的各个元素值,而这些值是用","分隔开来的。
你可以alert(query)看看,到底是什么内容。
?para1=value1¶2=value2
这样的格式,如果你这样写服务器端就能直接把query string分成一个一个的参数给你用,十分方便。实际上不这样写并没有违反规定,只是服务器端不认识罢了。所以用逗号来分隔也是完全正常的。
关于URL的规范:
http://www.w3.org/Addressing/URL/url-spec.txt