我有这样的JSON
数据:
var data = [
{"city":"seattle", "state":"WA", "population":652405, "land_area":83.9},
{"city":"new york", "state":"NY", "population":8405837, "land_area":302.6},
{"city":"boston", "state":"MA", "population":645966, "land_area":48.3},
{"city":"kansas city", "state":"MO", "population":467007, "land_area":315}
]
我已将此JSON
数据添加到HTML
表中。现在,如何在每次5 seconds
单击按钮时随机排列这些数据?
alter.addEventListener('click', function() {
//code goes here
})
给定的rows
是一个nodeListtr
function randomise() {
for (const row of rows) {
const table = row.parentElement;
table.insertBefore(
row,
table.children[Math.floor(Math.random() * table.children.length)]
);
}
}
alter.addEventListener("click", () => {
randomise();
setInterval(function () {
randomise();
}, 5000);
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句