本文介绍了随机加载子元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在使用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.
推荐答案
快点让我烦恼
- Remove all the items in the
<ul>
withdetach
- Store them in an array.
- Shuffle that array
- Insert elements in
<ul>
again.
还要看一下这个问题:随机化div元素
Also take a look at this question: randomize div elements
这篇关于随机加载子元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!