JS获取url链接字符串 location.href


js获取url链接字符串:location.href

可以对其进行截取,从而获取传送的参数,常用如下:

location.href.indexOf("?")------获取?的index值。

注意:这里的location.href可不是指的现在地址栏里的地址,而是页面实际的地址。

另外,一些题外话:

C#中获取字符所在位置的索引,也是用IndexOf来获取。

sqlserver中获取索引,就不同了:

第一种:

select * from dbo.users where CharIndex('2',mainsubjects)>0

第二种:
select * from dbo.users where patIndex('%2%',mainsubjects)>0

我使用通过判断栏目,来确定广告是否应该显示:

只有http://www.phpstudy.net/codes/目录的内容才显示广告:

复制代码 代码如下:

if(location.href.indexOf("http://www.phpstudy.net/codes/")>-1){
alert('ok');
}

« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3