[英]anchor tag href is different than what is set
I have an anchor tag that looks like this: 我有一个锚标签,看起来像这样:
<a href="/folder/folderid">name</a>
On click of this anchor tag I'm doing this 在点击此锚标记后,我正在执行此操作
handleAnchorClick: function(e) {
console.log("target:",e.target);
console.log("href:",e.target.href);
event.preventDefault();
// navigate to this folder using my app router
backbonerouter.navigate(e.target.href,{trigger:true}); //does not work as the value is wrong
// tries to navigate to this: mydomain.com/mydomain.com/folder/folderid
}
the console log statement gives me this: 控制台日志语句给了我这个:
target: <a href="/folder/folderid">name</a>
href: "https://mydomain.com/folder/folderid" //instead of just /folder/folderid
What the hell is going on, how do I navigate to this folder id using my router. 到底发生了什么,如何使用路由器导航到该文件夹ID。
The href property, as in element.href
, always returns an absolute URL containing the hostname etc. 与element.href
,href属性始终返回包含主机名等的绝对URL。
If you just want the attributes value and not the absolute URL, you can do 如果只需要属性值而不是绝对URL,则可以执行
e.target.getAttribute('href');
or with jQuery 或与jQuery
$(e.target).attr('href');
not that in jQuery prop() would return the property, ie the absolute URL 并非在jQuery prop()中会返回属性,即绝对URL
$(e.target).prop('href');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.