在js 中根据 url 获取其参数

本文介绍了一个JavaScript函数,用于从当前页面URL中解析出特定参数的值,如id、page、usersn和username等,并通过alert展示这些值。




None.gif function Edit()
ExpandedBlockStart.gifContractedBlock.gif         
dot.gif{
InBlock.gif          
var  url  =   window.location+"" ;
InBlock.gif       
InBlock.gif           
var id=''; 
InBlock.gif            
if (url.indexOf('&')==-1)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif              id
=  url.substring(url.indexOf("id=")+3,url.length); 
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{    
InBlock.gif            
var temp=url.indexOf("&");
InBlock.gif          
InBlock.gif            id
=url.substring(url.indexOf("id=")+3,url.indexOf("&"));
InBlock.gif            
InBlock.gif          
ExpandedSubBlockEnd.gif            }

InBlock.gif            alert(id);
InBlock.gif             
InBlock.gif           
var page=''
InBlock.gif             
InBlock.gif             
var urlpage=url.substring(url.indexOf("page="),url.length);
InBlock.gif             
InBlock.gif              
if (urlpage.indexOf("page=")!=-1)
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{  
InBlock.gif              
InBlock.gif                 
if (urlpage.indexOf("&")==-1)
ExpandedSubBlockStart.gifContractedSubBlock.gif                 
dot.gif{
InBlock.gif                  page
=urlpage.substring(urlpage.indexOf("page=")+5,urlpage.length);
ExpandedSubBlockEnd.gif                 }

InBlock.gif                 
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                 
dot.gif{
InBlock.gif                   page
=urlpage.substring (urlpage.indexOf("page=")+5,urlpage.indexOf("&"));
ExpandedSubBlockEnd.gif                 }

ExpandedSubBlockEnd.gif              }

InBlock.gif             
InBlock.gif             alert(page);
InBlock.gif             alert(urlpage);
InBlock.gif             
InBlock.gif             
InBlock.gif        
var  usersn="";
InBlock.gif        
InBlock.gif          
var urlsn=url.substring(url.indexOf("usersn="),url.length);
InBlock.gif           
if (urlsn.indexOf("usersn")!=-1)
ExpandedSubBlockStart.gifContractedSubBlock.gif           
dot.gif{
InBlock.gif              
if (urlsn.indexOf("&")==-1)
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                usersn
=urlsn.substring(urlsn.indexOf("usersn=")+7,urlsn.length);
ExpandedSubBlockEnd.gif              }

InBlock.gif              
else
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                 usersn
=urlsn.substring(urlsn.indexOf("usersn=")+7,urlsn.indexOf("&"));
ExpandedSubBlockEnd.gif              }

ExpandedSubBlockEnd.gif           }

InBlock.gif           
InBlock.gif           alert(usersn);
InBlock.gif           
InBlock.gif           
InBlock.gif           
InBlock.gif           
InBlock.gif            
var username="";
InBlock.gif            
InBlock.gif             
var urlname=url.substring(url.indexOf("username="),url.length)
InBlock.gif              
if (urlname.indexOf("username")!=-1)
ExpandedSubBlockStart.gifContractedSubBlock.gif                  
dot.gif{
InBlock.gif                     
if(urlname.indexOf("&")==-1)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif
InBlock.gif                 
InBlock.gif                     username
=urlname.substring (urlname.indexOf("username=")+9,urlname.length);
InBlock.gif                     
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
else 
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                    username
=urlname.substring(urlname.indexOf("username=")+9,urlname.indexOf("&"));
InBlock.gif                    
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
ExpandedSubBlockEnd.gif                  }

InBlock.gif                  
InBlock.gif                alert(username);
InBlock.gif                  
InBlock.gif                  
InBlock.gif            
InBlock.gif          
InBlock.gif              
InBlock.gif                 
InBlock.gif   
InBlock.gif          
InBlock.gif        
InBlock.gif           
InBlock.gif          
ExpandedBlockEnd.gif         }

转载于:https://www.cnblogs.com/gwazy/archive/2006/06/14/425605.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值