宜昌本地软件开发与弱电工程服务商
项目咨询 · 快速响应

[JS]js取html文件所带的参数值

2016-10-13 00:16:48 点击量:91 标签: 收藏本文

[JS]js取html文件所带的参数值

  1. <a href=3.html?qq=1&ww=2&aa=3>测试</a> 
  2. <script> 
  3. function chk() 
  4. { 
  5. if(location.search=="") 
  6. { 
  7. return false 
  8. } 
  9. var s=location.search 
  10. alert(s.substr(1,s.length).split("&")[0]); 
  11. alert(s.substr(1,s.length)); 
  12. } 
  13. //window.onload=chk 
  14. </script>  
  15.  
  16.  
  17.  
  18. <script> 
  19. function GetRequest() 
  20. { 
  21.  var url = location.search; //获取url中"?"符后的字串 
  22.  var theRequest = new Object(); 
  23.  if(url.indexOf("?") != -1) 
  24.  {  
  25.   var str = url.substr(1); 
  26.   strstrs = str.split("&"); 
  27.   for(var i = 0; i < strs.length; i ++) 
  28.   {  
  29.    theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]); 
  30.   } 
  31.  } 
  32. return theRequest; 
  33. } 
  34. </script> 
  35.  
  36. <script> 
  37. var Request=new Object(); 
  38. Request=GetRequest(); 
  39. var i,o,p; 
  40. i=Request['qq']; 
  41. o=Request['ww']; 
  42. p=Request['aa']; 
  43. //alert(i); 
  44. //alert(o); 
  45. alert(p); 
  46. </script>