日期:2014-05-16  浏览次数:20355 次

js取得IE地址栏指定参数的值

2010-6-22 X二

<script language="JavaScript">
function getQueryString(key){
??? var searchString = document.location.search.toString();
??? var returnValue = '';
??? if (searchString.substr(0,1)=='?' && searchString.length>1)
??? {
??????? var queryString = searchString.substring(1,searchString.length)
??????? var queryList = queryString.split('&');
??????? for (var i=0; i<queryList.length; i++)
??????? {
??????????? var oneQuery = queryList[i].split('=');
??????????? if (oneQuery[0]==key && oneQuery.length==2)
??????????? {
??????????????? returnValue = oneQuery[1];
??????????? }
??????? }
??? }
??? return returnValue;
}
</script>

?

<script>

document.write(getQueryString('id'));

alert(getQueryString('id'));
</script>

<a href="?id=90">aaaaaaaa </a>