给a标签绑定点击事件,取得this.hostname
当a标签的href="javascript:;"之类的时候,返回""
当a标签的href="http://www.某某某.com/index.php?cid=121&tid=11432"时,返回www.某某某.com
当如下:http://www.某某某.com/index.html?tab=0时,却返回""。(tab没有实际意义,用来判断页面某内容是否显示)
这是为什么呢?
给a标签绑定点击事件,取得this.hostname
当a标签的href="javascript:;"之类的时候,返回""
当a标签的href="http://www.某某某.com/index.php?cid=121&tid=11432"时,返回www.某某某.com
当如下:http://www.某某某.com/index.html?tab=0时,却返回""。(tab没有实际意义,用来判断页面某内容是否显示)
这是为什么呢?
你意思是说html后缀的就取不到hostname吗?我没研究过,但是几遍这种方式取不到也有很多别的方式啊,比如你用正则在url里面取你想要
的hostname,也很简单
window.location.href.split("//")[1].split("/")[0]