js获取锚点名称 #

var thisId = window.location.hash;
alert(thisId);

输出

#2

原文地址:https://www.cnblogs.com/wesky/p/4621127.html