代码
<script type="text/javascript">
<!--
function getvalue(name)
{
var str=window.location.search;
if (str.indexOf(name)!=-1)
{
var pos_start=str.indexOf(name)+name.length+1;
var pos_end=str.indexOf("&",pos_start);
if (pos_end==-1)
{
return str.substring(pos_start);
}
else
{
return str.substring(pos_start,pos_end)
}
}
else
{
return "";
}
}
//for test: http://localhost/a.html?p1=11&p2=22
document.write(location.search);
alert(getvalue("p1"));
alert(getvalue("p2"));
//-->
</script>
<!--
function getvalue(name)
{
var str=window.location.search;
if (str.indexOf(name)!=-1)
{
var pos_start=str.indexOf(name)+name.length+1;
var pos_end=str.indexOf("&",pos_start);
if (pos_end==-1)
{
return str.substring(pos_start);
}
else
{
return str.substring(pos_start,pos_end)
}
}
else
{
return "";
}
}
//for test: http://localhost/a.html?p1=11&p2=22
document.write(location.search);
alert(getvalue("p1"));
alert(getvalue("p2"));
//-->
</script>