Double color ball function code sharing implemented by JS
This article mainly introduces the double-color ball function implemented by native JS, involving javascript random number generation and numerical operation related operation skills. Friends in need can refer to it, I hope it can help everyone.
Let’s take a look at the running effect first:
The specific code is as follows:
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>www.jb51.net - JS双色球</title> <style> #datePicker { width: 100px; height: 30px; line-height: 30px;; border-radius: 10px; border: 1px solid #5098a5; text-align: center; cursor: pointer; } #number { height: 100px; float: left; margin-top: 20px; } #number span { display: block; width: 30px; height: 30px; line-height: 30px; text-align: center; border-radius: 30px; border: 2px solid red; color: red; font-weight: bold; float: left; margin-top: 15px; margin-right: 10px; } #buleBall { height: 100px; margin-top: 21px; float: left; } #buleBall span { display: block; width: 30px; height: 30px; line-height: 30px; text-align: center; border-radius: 30px; background-color: blue; color: white; font-weight: bold; float: left; margin-top: 15px; margin-right: 10px; } </style> </head> <body> <p class="container"> <p style="overflow:hidden;"> <p id="number"></p> <p id="buleBall"></p> </p> <p id="datePicker">点击按钮</p> </p> <script> //循环产生1-36数字 var arr = []; function num() { for (var i = 1; i < 34; i++) { arr.push(i); } confusion(); } var arrty= new Array(arr); //伪随机方法 function confusion(){ for(var i=1;i<34;i++){ arrty[i]=i; } arrty.sort(function(){ return 0.5 - Math.random() }); // var str=arrty.join(); arrAy() } // 将随机获取的数据添加到页面上去 function arrAy() { var array = getRandomArrayElements(arrty, 6); array.sort(function (a, b) {//数组排序 return a > b ? 1 : -1; }); var htm = ""; for (var i = 0; i < array.length; i++) { htm += '<span>' + array[i] + '</span>'; } document.getElementById('number').innerHTML = htm; } // 从1-36中随机取出其中6个参数 function getRandomArrayElements(arr, count) { var shuffled = arr.slice(0), i = arr.length, min = i - count, temp, index; while (i-- > min) { index = Math.floor((i + 1) * Math.random()); temp = shuffled[index]; shuffled[index] = shuffled[i]; shuffled[i] = temp; } return shuffled.slice(min); } //随机获取一个蓝球的方法 function blueBall() { var html = ""; var array = []; for (var k = 1; k < 17; k++) { array.push(k); } //随机生成蓝色球的算法 var n = Math.floor(Math.random() * array.length); if (n != "0") {//去除获取到的篮球数为0的 html += '<span>' + n + '</span>'; } document.getElementById('buleBall').innerHTML = html; } window.onload = function () { var datePicker = document.getElementById("datePicker"); datePicker.onclick = function () { num();//点击按钮生成1-33的数字方法 blueBall();//点击后获取随机蓝球的方法 }; } </script> </body> </html>
Related recommendations :
Examples introduce the use of python random numbers, derivation and strings, Shuangseqiu
2 ways to randomly generate Welfare Lottery Shuangseqiu numbers using PHP _PHP Tutorial
Two methods of randomly generating welfare lottery numbers with php
The above is the detailed content of Double color ball function code sharing implemented by JS. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Quark Netdisk and Baidu Netdisk are very convenient storage tools. Many users are asking whether these two softwares are interoperable? How to share Quark Netdisk to Baidu Netdisk? Let this site introduce to users in detail how to save Quark network disk files to Baidu network disk. How to save files from Quark Network Disk to Baidu Network Disk Method 1. If you want to know how to transfer files from Quark Network Disk to Baidu Network Disk, first download the files that need to be saved on Quark Network Disk, and then open the Baidu Network Disk client. , select the folder where the compressed file is to be saved, and double-click to open the folder. 2. After opening the folder, click "Upload" in the upper left corner of the window. 3. Find the compressed file that needs to be uploaded on your computer and click to select it.

How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

1. First, we enter NetEase Cloud Music, and then click on the software homepage interface to enter the song playback interface. 2. Then in the song playback interface, find the sharing function button in the upper right corner, as shown in the red box in the figure below, click to select the sharing channel; in the sharing channel, click the "Share to" option at the bottom, and then select the first "WeChat Moments" allows you to share content to WeChat Moments.

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

Recently, Baidu Netdisk Android client has ushered in a new version 8.0.0. This version not only brings many changes, but also adds many practical functions. Among them, the most eye-catching is the enhancement of the folder sharing function. Now, users can easily invite friends to join and share important files in work and life, achieving more convenient collaboration and sharing. So how do you share the files you need to share with your friends? Below, the editor of this site will give you a detailed introduction. I hope it can help you! 1) Open Baidu Cloud APP, first click to select the relevant folder on the homepage, and then click the [...] icon in the upper right corner of the interface; (as shown below) 2) Then click [+] in the "Shared Members" column 】, and finally check all

Mango TV has various types of movies, TV series, variety shows and other resources, and users can freely choose to watch them. Mango TV members can not only watch all VIP dramas, but also set the highest definition picture quality to help users watch dramas happily. Below, the editor will bring you some free Mango TV membership accounts for users to use, hurry up and take a look Take a look. Mango TV latest member account free sharing 2023: Note: These are the latest member accounts collected, you can log in directly and use them, do not change the password at will. Account number: 13842025699 Password: qds373 Account number: 15804882888 Password: evr6982 Account number: 13330925667 Password: jgqae Account number: 1703

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

Title: To solve the problem that Discuz WeChat shares cannot be displayed, specific code examples are needed. With the development of the mobile Internet, WeChat has become an indispensable part of people's daily lives. In website development, in order to improve user experience and expand website exposure, many websites will integrate WeChat sharing functions, allowing users to easily share website content to Moments or WeChat groups. However, sometimes when using open source forum systems such as Discuz, you will encounter the problem that WeChat shares cannot be displayed, which brings certain difficulties to the user experience.
