【发布时间】:2021-01-31 10:03:40
【问题描述】:
例如我有代码:
<a class="link" href="https://example1.com">example1</a>
<a class="link" href="https://example2.com">example2</a>
<a class="link" href="https://example3.com">example3</a>
需要使用类“链接”获取元素的所有属性“href” 示例输出:
https://example1.com
https://example2.com
https://example3.com
我有脚本,但它总是得到第一个元素:
let i = 0;
let b = 3;
while (i < 3) {
var href = $('.link').attr('href');
console.log(href);
i++;
}
如何在下一个元素处切换?
【问题讨论】:
标签: javascript jquery web