您现在的位置是:首页 > 电脑技术查询 > web开发

怎么获取当前网址的定位锚值

编辑:chaxungu时间:2022-10-02 23:20:40分类:web开发

如何获取当前网址的定位锚值?
如何获取当前网址的定位锚值?
如,当前网址:http://www.xxx.com/xx.htm#test
如何通过javascript或其他手段得到定位锚值 test ???

------解决方案--------------------
var url = 'http://www.xxx.com/xx.htm#test ';
alert(url.substr(url.indexOf( '# ') + 1));
------解决方案--------------------
var h = document.location.hash;
if(h!= " ") h = h.substr(1,h.length-1);
alert(h);
------解决方案--------------------
document.location.hash.subString(1)