window.onload = function (){
var hrefs = document.getElementById( ' hrefs ' );
var links = hrefs.getElementsByTagName( ' a ' );
for ( var i = 0 , n = links.length; i < n; i ++ ){
links[i].onclick = function (){
var urls = this .getAttribute( ' href ' );
var params = urls.split( ' ? ' );
for ( var i = 0 ; i < params[ 1 ].length; i ++ ){
var p = params[ 1 ].split( ' = ' );
var pValue = p[ 1 ];
clickAdd(pValue);
return false ;
}
}
}
}
function clickAdd(v){
document.getElementById( ' target ' ).innerHTML = v;
}
< div id ="hrefs" >
< a href ="/sub.html?id=1" > aaaa </ a >< br >
< a href ="/sub.html?id=2" > 2222 </ a >< br >
< a href ="/sub.html?id=3" > 3333 </ a >< br >
< a href ="/sub.html?id=4" > 4444 </ a >< br >
< a href ="/sub.html?id=5" > 5555 </ a >< br >
</ div >
< div id ="target" > 这里是值 </ div >
动态得到链接的参数,也没有什么技术含量,只是做为一走过的历程,记录下来。
强化后的:
window.onload = function (){
var hrefs = document.getElementById( ' hrefs ' );
var links = hrefs.getElementsByTagName( ' a ' );
for ( var i = 0 , n = links.length; i < n; i ++ ){
links[i].onclick = function (){
var urls = this .getAttribute( ' href ' );
var params = urls.split( ' ? ' );
var pV = params[ 1 ].split( ' & ' );
for ( var j = 0 ; j < pV.length; j ++ ){
var p = pV[j].split( ' = ' );
var pName = p[ 0 ];
var pValue = p[ 1 ];
document.getElementById( ' target ' ).innerHTML += ' <br /> name = ' + pName + ' value = ' + pValue + ' <br /> ' ;
}
return false ;
}
}
}
本文转自豪情博客园博客,原文链接:http://www.cnblogs.com/jikey/archive/2009/12/08/1619692.html,如需转载请自行联系原作者