[英]anchor tag href is different than what is set
我有一個錨標簽,看起來像這樣:
<a href="/folder/folderid">name</a>
在點擊此錨標記后,我正在執行此操作
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
}
控制台日志語句給了我這個:
target: <a href="/folder/folderid">name</a>
href: "https://mydomain.com/folder/folderid" //instead of just /folder/folderid
到底發生了什么,如何使用路由器導航到該文件夾ID。
與element.href
,href屬性始終返回包含主機名等的絕對URL。
如果只需要屬性值而不是絕對URL,則可以執行
e.target.getAttribute('href');
或與jQuery
$(e.target).attr('href');
並非在jQuery prop()中會返回屬性,即絕對URL
$(e.target).prop('href');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.