var a = document.createElement('a');
a.href = '/path';
// will give the absolute url: http://.../path
console.log(a.href);
a.href是否有可能在不修改返回值的情况下返回原始相对路径'/ path'?
答案 0 :(得分:0)
这应该这样做 -
var a = document.createElement('a');
a.href = '/path';
var domain = window.location.origin;
console.log(a.href.substring(domain.length));