有时候我们需要获取当前网页的网址,方便我们判断,一般情况我们都是通过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 代码如下: if(location.href.indexOf("http://www.jb51.net/codes/")>-1){ alert('ok'); }