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

Use native JS to implement pop-up layer effects_javascript skills Use native JS to implement pop-up layer effects_javascript skills

16 May 2016

This article mainly introduces the use of native JS to implement pop-up layer special effects. Friends in need can refer to it.

Code to implement gradient background effects using JS and CSS Code to implement gradient background effects using JS and CSS

11 Jun 2018

This article mainly introduces the beautiful gradient background special effects code implemented by JS and CSS, including 6 gradient effects, involving JavaScript related skills for dynamic operation of page element attributes. Friends in need can refer to it.

How to implement Transformers text special effects code sharing in js How to implement Transformers text special effects code sharing in js

08 Sep 2017

The js Transformers text special effects code shared with everyone is as follows--------------------------------------------- --------Effect Demonstration---------------------------------------- ------- &lt;head> &lt;meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> &lt;

Native JS+Canvas code to implement backgammon game Native JS+Canvas code to implement backgammon game

03 Jul 2018

This article mainly introduces the implementation of the backgammon game with native JS+Canvas in detail. It has certain reference value. Interested friends can refer to it.

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

HTML5 selected special effects code sharing (collection) HTML5 selected special effects code sharing (collection)

01 Mar 2019

In the process of web design, we often use some HTML5 special effects codes. Here are some cool and practical HTML5 special effects codes compiled and shared by php Chinese website. You can feel free to use them in your applications.

js code to implement small squares with random colors_Basic knowledge js code to implement small squares with random colors_Basic knowledge

16 May 2016

This article mainly uses js code to implement small squares with random colors. Friends who need it can refer to it.

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

Recommended 3 articles about video fragmentation and reorganization Recommended 3 articles about video fragmentation and reorganization

15 Jun 2017

Applications based on HTML5 are now very widespread. Today we will share with you 20 very gorgeous HTML5/CSS3 application plug-ins. Hope you all like it and share it with your friends. 1. HTML5 video breaking and reorganization special effects. Powerful visual impact. There are many HTML5 video players, but HTML5 video special effects are still rare. This HTML5 video breaking and reorganization special effect is very exciting and gives people a strong visual impact. Click anywhere in the video, and HTML5 will break these areas into pieces. After a while, these broken video fragments will automatically reassemble...

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.