![](/img/trans.png)
[英]how to GET and store specific values as a list from JSON data(URL) in javascript?
[英]Get a specific url from a list with javascript
<p class="URL-List">
Download :
<a href="https://exampleAA.com"><strong>AA</strong></a> /
<a href="https://exampleBB.com"><strong>BB</strong></a> /
<a href="https://exampleCC.com"><strong>CC</strong></a>
</p>
我的代码
AA = URL[0].getElementsByTagName("a")
AA[0]
我会得到第一个 URL:
但是名单变了
<p class="URL-List">
Download :
<a href="https://exampleCC.com"><strong>CC</strong></a> /
<a href="https://exampleDD.com"><strong>DD</strong></a> /
<a href="https://exampleSS.com"><strong>SS</strong></a> /
<a href="https://exampleAA.com"><strong>AA</strong></a> /
<a href="https://exampleFF.com"><strong>FF</strong></a> /
<a href="https://exampleBB.com"><strong>BB</strong></a>
</p>
我的代码
AA = URL[0].getElementsByTagName("a")
AA[0]
现在我得到:`
`但我想要
我怎样才能找到那个特定的 URL?
如果你知道你想要哪个链接,你可以使用.querySelector()
和属性选择器语法:
let myLink = document.querySelector("a[href='https://exampleAA.com']"); console.log(myLink.textContent, myLink.href);
<p class="URL-List"> Download : <a href="https://exampleCC.com"><strong>CC</strong></a> / <a href="https://exampleDD.com"><strong>DD</strong></a> / <a href="https://exampleSS.com"><strong>SS</strong></a> / <a href="https://exampleAA.com"><strong>AA</strong></a> / <a href="https://exampleFF.com"><strong>FF</strong></a> / <a href="https://exampleBB.com"><strong>BB</strong></a> </p>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.