Code to implement native js random ordering
code segment:
window.onload = function(){
var btn = document.getElementById('btn');
var cm = document.getElementById('cm');
// Get the menu in html
var menu = document.getElementsByTagName('span');
var menuList = [];
// Traverse the menus and add them one by one to the new menu menuList array
for(var i=0;i<menu.length;i++){
menuList.push(menu[i].innerHTML);
}
btn.onclick = function(){
var num = Math.floor(Math.random()*(menuList.length-1+1-0)+0);
cm.innerHTML = menuList[num];
}
}
All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn
Related Article
![How to Implement Pagination with Random Ordering in PHP MySQL?](https://img.php.cn/upload/article/001/246/273/172972782335906.jpg)
24 Oct 2024
This article discusses the issue of ordering search results on a website's content page using a pagination system. It explores the problem of excluding previously seen results, maintaining search result freshness on the first page, and the practical
![How to Implement Pagination with Random Ordering in PHP and MySQL?](https://img.php.cn/upload/article/001/246/273/172972806363467.jpg)
24 Oct 2024
This article addresses the challenges encountered when implementing search functionality with pagination on a website, specifically related to the random ordering of results. It provides solutions to ensure that previously seen results are excluded o
24 Jun 2016
61 web page special effects that are very fashionable and have great visual effects
24 Jun 2016
Animation loading special effects implemented in pure css3
![jquery waterfall flow LightBox picture box special effects](http://static.oschina.net/uploads/code/201607/05154721_nehQ.gif)
06 Jul 2016
jquery waterfall flow LightBox picture box special effects
24 Jun 2016
A batch of hover special effects implemented by CSS3
24 Jun 2016
Revealing the special effects in Tencent’s Burberry event page
![See all articles](/static/imghw/down_right.png)
![](/static/imghw/taglogo.png)
Hot Tools
![HTML5 Canvas heart fluttering animation special effects](https://img.php.cn/upload/jscode/000/000/001/58da180947f26347.jpg)
HTML5 Canvas heart fluttering animation special effects
HTML5 Canvas heart fluttering animation special effect is a generated animation that can be directly opened with a browser to see a heart.
![H5 panda bouncing game source code](https://img.php.cn/upload/jscode/000/000/164/5d5e5b326606a398.jpg)
H5 panda bouncing game source code
HTML5 Mobile Panda is also a crazy game source code. Game description: Press and hold the screen to adjust the strength of the panda spring and jump to the stone pillar. The game ends if you fall into the river.
![HTML5 Valentine's Day box animation special effects](https://img.php.cn/upload/jscode/000/287/557/62060ef97eb52905.png)
HTML5 Valentine's Day box animation special effects
Based on svg, draw animations of opening love box gifts on Valentine's Day, and special effects of love box animation.
![H5 3D rolling ball game source code](https://img.php.cn/upload/jscode/000/000/164/5d633774de4a9799.jpg)
H5 3D rolling ball game source code
HTML5 cool 3D ball rolling mobile game code download. Game introduction: A colored ball rolls, and the current track of the colored ball is controlled by dragging it with the mouse or the touch screen of the mobile phone. This is a simple and easy-to-operate mobile game source code.
![](/static/imghw/taglogo.png)