JavaScript randomly generates phone numbers via regular

Source: Internet
Author: User

Without an interface, you can only simulate JSON data yourself.

Just need to simulate some phone numbers, I do not bother to write freely,

Instead of writing a small function to implement a randomly generated phone number

<!DOCTYPE HTML><HTMLLang= "en"><Head>    <MetaCharSet= "UTF-8">    <Metaname= "Viewport"content= "Width=device-width, initial-scale=1.0">    <Metahttp-equiv= "X-ua-compatible"content= "Ie=edge">    <title>Randomly generated phone numbers</title>    <style>ul Li{List-style:None;        }    </style></Head><Body>    <Buttonclass= "BTN"value="">Start generating phone numbers</Button>    <Buttonclass= "BTN1"value="">Stop it</Button>    <Buttonclass= "BTN2"value="">Clear page</Button>    <ulclass= "Autonum"></ul>    <Script>        varnn=Document.getelementsbyclassname ("Autonum")[0]; varLilength=document.getElementsByTagName ("Li"); varBtnon=Document.getelementsbyclassname ("btn")[0]; varbtnOn1=Document.getelementsbyclassname ("BTN1")[0]; varbtnOn2=Document.getelementsbyclassname ("btn2")[0]; vartimer; Btnon.addeventlistener ('Click', function() {Console.log ("function StarT"); Timer=SetInterval (function() {autoNum1 ();            Autostop (timer); },  -); }, false); Btnon1.addeventlistener ('Click', function() {clearinterval (timer);        Console.log (lilength.length); }, false); Btnon2.addeventlistener ('Click', function() {clearinterval (timer);        Clearnum (); }, false); //clear all the numbers.        functionClearnum () {console.log (lilength.length);  for (varI=Lilength.length-1; I>=0; I--) {nn.removechild (nn.childnodes[i]); }        }        //Stop Timer        functionAutostop (timer) {if(Lilength.length> Ten) {clearinterval (timer); Console.log ("By 11, STOP."); }        }        //automatically generate phone numbers        functionautoNum1 () {Console.log ("phone number start generation")            varNuM= []; //generate phone numbers from random functions and store them in an array             for (varI= 0; I<  One; I++) {                varNum=Math.floor (Math.random ()* Ten);            Num.unshift (num); }            //remove the comma from the array by the Join methodNuM=Num.join (""); //determine if the number is the normal number by regular            if ((/^1[34578]\d{9}$/. Test (NuM))) {                //alert ("found");NuM=num.tostring (); varnode=Document.createelement ("Li"); //Create an Li node                varTextnode=document.createTextNode (NuM);//Create a text node contentNode.appendchild (textnode);//Add the contents of the text node to the LI node                //document.getElementById ("test"). AppendChild (node), and//Add the Li node to the test under what time                //var createnum = "<li>" + NuM + "</p>";nn.appendchild (node); }        }    </Script></Body></HTML>

JavaScript randomly generates phone numbers via regular

Related Article

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.