我对如何洗牌要素感到有些沮丧(因为我有数据存储在它们中,只是简单地改变文本就不够)。我试图洗牌兄弟元素,所以我应该使用.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);
}
那么它有什么问题?它不起作用吗? 你没有说明你的问题... –