In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the knowledge of "how to use JS to write Mini Program with randomly selected numbers". In the operation of practical cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The functions of this program are as follows:
1. Enter the maximum value of the draw in the text box
2. Click the button, start drawing numbers, and randomly generate integers between 1 and the maximum.
3. The number that has been extracted cannot be extracted again to ensure the uniqueness of the number.
4. Display the number result in result.
5. Store the generated number in exist and display it.
The specific code is as follows:
Results: extracted: var oBtn = document.getElementById ("btn"); var oTxt = document.getElementById ("txt"); var oRes = document.getElementById ("result"); var oExi = document.getElementById ("exist"); var arr = []; / / seat number oBtn.onclick = function () {getSeat (oTxt.value);} function getSeat (maxnum) {for (var I = 0; I)
< maxnum; i++){ var num = Math.floor(Math.random() * maxnum) + 1; var j; for(j = 0; j < arr.length; j++) { if(num == arr[j]) break; } if(j == arr.length) { arr.push(num); oRes[xss_clean] = num; oExi[xss_clean] = arr; return; } } } 运行结果如下:This is the end of "how to use JS to write Mini Program with randomly selected numbers". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.