How to get all href attributes values of
<ul>
<li class="demo">
<a href="/chat/2"></a>
</li>
<li class="demo">
<a href="/chat/3"></a>
</li>
</ul>
How can I get Href attributes values in one array?
答案 0 :(得分:0)
var Arr=[];
$("li.demo").each(function(){
Arr.push($(this).find("a").attr("href"));
});
console.log(Arr);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
<li class="demo">
<a href="/chat/2"></a>
</li>
<li class="demo">
<a href="/chat/3"></a>
</li>
</ul>
答案 1 :(得分:-1)
let foo = document.getElementsByTagName("a");
console.log(foo)
let my_array = [];
for(let i=0;i<foo.length;i++) {
my_array.push(foo.item(i).href);
}
console.log(my_array)
&#13;
<ul>
<li class="demo">
<a href="/chat/2"></a>
</li>
<li class="demo">
<a href="/chat/3"></a>
</li>
</ul>
&#13;