ページが更新されるたびにこの表示をランダムな順序で行うにはどうすればよいですか。javascript - ページが更新されるたびにランダムな順序で表示
ここで私は自分のワードプレスのテキストエディタに追加したものですが、画像は完璧に表示されますが、divの順番はランダム化されません。私は何を間違えたのですか?
<br><br>
<div class="quiz">
<a href="http://www.thequizmania.com/we-bet-you-cant-pass-this-tricky-general-knowledge-quiz/">
<img src="http://i.imgur.com/3YcBoyN.jpg"></img>
<a>
</div>
<br>
<div class="quiz">
<a href="http://www.thequizmania.com/what-kind-of-traveler-are-you/">
<img src="http://i.imgur.com/GZn9myC.jpg"></img>
<a>
</div>
<br>
<div class="quiz">
<a href="http://www.thequizmania.com/what-two-words-describe-you-as-a-mother/">
<img src="http://i.imgur.com/QnJezBF.jpg"></img>
<a>
</div>
<br>
<div class="quiz">
<a href="http://www.thequizmania.com/can-you-pick-the-correct-word/">
<img src="http://i.imgur.com/Pdi9dyo.jpg"></img>
<a>
</div>
<br>
<div class="quiz">
<a href="http://www.thequizmania.com/can-you-pass-this-almost-impossible-shapes-test/">
<img src="http://i.imgur.com/Ov5WdOg.jpg"></img>
<a>
</div>
<br>
<script>
var cards = $(".quiz");
for(var i = 0; i < cards.length; i++){
var target = Math.floor(Math.random() * cards.length -1) + 1;
var target2 = Math.floor(Math.random() * cards.length -1) +1;
cards.eq(target).before(cards.eq(target2));
}
</script>
ところで、あなたは終了タグ '' '' ''どこでも – Optio
さて、あなたに感謝しませんでしたその@Optioについてはまだ助けにならなかった。 –
クラス 'quiz'を持つ要素の数を取得し、ランダムにソートされた1〜nの数の配列を作成し、このランダム化された数値の配列を参照して要素をランダムにソートすることができます。 @Mehul Mohanの答えを見てください。 –