我對如何洗牌要素感到有些沮喪(因爲我有數據存儲在它們中,只是簡單地改變文本就不夠)。我試圖洗牌兄弟元素,所以我應該使用.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);
}
那麼它有什麼問題?它不起作用嗎? 你沒有說明你的問題... –