随机加载子元素 [英] Randomize children elements on load

查看:50
本文介绍了随机加载子元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在使用JavaScript加载时随机化任何<div><ul>的子元素.我正在寻找最好的方法来做到这一点.有人可以帮忙吗?

I want to randomize the children elements of any <div>, <ul> on load with javascript. I am searching for the best approach to do it. Can some one help?

假设我有一个带有5个<li>元素的<ul>.在加载时,我希望<li>元素以随机顺序出现.

Suppose i have a <ul> with 5 <li> elements. On load i want the <li> elements to appear in random order.

推荐答案

快点让我烦恼

  1. 使用 detach
  2. 删除<ul>中的所有项目.
  3. 将它们存储在数组中.
  4. 随机播放该数组
  5. 再次在<ul>中插入元素.
  1. Remove all the items in the <ul> with detach
  2. Store them in an array.
  3. Shuffle that array
  4. Insert elements in <ul> again.

还要看一下这个问题:随机化div元素

Also take a look at this question: randomize div elements

这篇关于随机加载子元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆