实际上,我需要两个数组,来自两个属性“id_play”和“orden_play”。
我在这里分享我的代码:
let id_play = [];
let orden_play = [];
id_play = $("#listaOrdenable").children().attr('id_play');
orden_play = $("#listaOrdenable").children().attr('orden_play');
<ul id="listaOrdenable" class="s1">
<li orden_play="0" id_play="47"><img src="uploads/meade.jpg" width="40" heigth="40">1</li>
<li orden_play="1" id_play="49"><img src="uploads/videoIcon.png" width="40" heigth="40">2</li>
<li orden_play="2" id_play="50"><img src="uploads/RARA.jpg" width="40" heigth="40">3</li>
<li orden_play="3" id_play="51"><img src="uploads/videoIcon.png" width="40" heigth="40">4</li>
</ul>
最佳答案
let id_play = [];
let orden_play = [];
const children = $("#listaOrdenable").children().map((childId, child) => child.attributes);
const getAttrFromChild = (attr) => children.get().map(child => child[attr].value);
id_play = getAttrFromChild("id_play")
orden_play = getAttrFromChild("orden_play")
console.log(id_play, orden_play)
关于Javascript,如何将标签属性中的所有值放入数组中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53462356/