我对如何随机播放元素有点沮丧(因为我在其中存储了数据,仅仅更改文本是不够的)。我正在尝试洗牌兄弟元素,所以我应该使用 .before 和 .after。这是我当前的代码
function shuffle() {
var children = $("#paren").children();
randIndex = randomFromTo(0, arr.length - 1);
for(i = 0; i < children.length; i++) {
//But obviously I can't retrieve a specific child like this
$("#parent nth-child("+randIndex+")").before(children.i);
}
}
function randomFromTo(from, to){
return Math.floor(Math.random() * (to - from + 1) + from);
}