Home JS special effects html5 special effects Code to implement native js random ordering

Code to implement native js random ordering

Code to implement native js random ordering

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];
}
}

Disclaimer

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? How to Implement Pagination with Random Ordering in PHP MySQL?

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? How to Implement Pagination with Random Ordering in PHP and MySQL?

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

css special effects_html/css_WEB-ITnose css special effects_html/css_WEB-ITnose

24 Jun 2016

css special effects

HTML&css&j special effects_html/css_WEB-ITnose HTML&css&j special effects_html/css_WEB-ITnose

24 Jun 2016

HTML&css&j special effects

61 web page special effects, very fashionable and with good visual effects_html/css_WEB-ITnose 61 web page special effects, very fashionable and with good visual effects_html/css_WEB-ITnose

24 Jun 2016

61 web page special effects that are very fashionable and have great visual effects

Animated loading effects implemented in pure css3_html/css_WEB-ITnose Animated loading effects implemented in pure css3_html/css_WEB-ITnose

24 Jun 2016

Animation loading special effects implemented in pure css3

jquery waterfall flow LightBox picture box special effects jquery waterfall flow LightBox picture box special effects

06 Jul 2016

jquery waterfall flow LightBox picture box special effects

A batch of hover effects implemented by CSS3_html/css_WEB-ITnose A batch of hover effects implemented by CSS3_html/css_WEB-ITnose

24 Jun 2016

A batch of hover special effects implemented by CSS3

Revealing the special effects in Tencent's burberry event page_html/css_WEB-ITnose Revealing the special effects in Tencent's burberry event page_html/css_WEB-ITnose

24 Jun 2016

Revealing the special effects in Tencent’s Burberry event page

See all articles See all articles

Hot Tools

HTML5 Canvas heart fluttering animation special effects

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

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

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

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.