A simple JavaScript code for extracting random numbers

Source: Internet
Author: User

A simple js to extract random numbersSource code

I wrote an example of JS random number extraction. For your reference in the future.

SourceCodeAs follows:

<HTML> <br/> <pead> <br/> <meta http-equiv = "Content-Type" content = "text/html; charset = gb2312 "> <br/> <MCE: script language =" JavaScript "type =" text/JavaScript "> <! -- <Br/> var IDs = "1001,1002, 1003,1004, 1005,1006, 1007,1008, 1009"; // extract range, separated by commas (,). Here is the interface: you can use el to obtain the background input data <br/> var idsarr = IDs. split (","); <br/> var num = idsarr. length-1; // number of extracts <br/> var timer; // defines the timer </P> <p> Function Change () {<br/> document. getelementbyid ("expertid "). value = idsarr [getend (0, num)]; // quick conversion of extracted values <br/>}< br/> function startext () {<br/> clearinterval (timer); // cancel the timer <br/> timer = setinterval ('change () ', 10); // 10 (millisecond) the smaller the transformation interval, the faster the transformation <br/>}< br/> function endext () {<br/> clearinterval (timer ); // cancel the timer <br/>}< br/> function getend (Min, max) {<br/> return parseint (math. random () * (max-min + 1); // random extraction <br/>}</P> <p> // --> </MCE: SCRIPT> <br/> </pead> <br/> <body> <br/> <Table> <br/> <tr> <br/> <TD align =" right "colspan =" 8 "> <br/> <input type =" button "value =" start to extract "onclick =" startext (); "Name =" button4 "> <br/> <input type =" text "id =" expertid "value =" "name =" expertid "style =" width: 150px; height: 70px; color: red; font-size: 70px; Border: 0px; Background: Background-color; border-left: none; border-Right: none; border-top: none; border-bottom: none; text-align: right; "readonly> <br/> <input type =" button "value =" stop extraction "onclick =" endext (); "Name =" button5 "> <br/> </TD> <br/> </tr> <br/> </table> <br/> </body> <br/> </ptml>

Run:

Source code: A simple JavaScript code for extracting random numbers.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.