【发布时间】:2021-02-05 16:55:40
【问题描述】:
给定以下锚点:
<a class="example" href="record1234">link</a>
如何使用 vanilla Javascript 检索 href 的实际值?
const link = document.querySelector('.example');
console.log(link.href);
// https://exampledomain.com/current/document/path/record1234
console.log(link.pathname)
// /current/document/path/record1234
// with jQuery
$('.example').attr('href');
// what I want to do:
console.log(link.href.string); // record1234
【问题讨论】:
标签: javascript