Javascript-javascript tutorial

Source: Internet
Author: User
This article describes how to generate random numbers that are not repeated in javascript within a specified range and related examples. If you need them, refer. Source of question: one test question when learning jQuery in MOOC.

Initial:
 
 
    Only 5 elements are displayed.
  • Element, including the last
  • "More" characters are displayed in the element. When you click "more", the content of the link becomes "simplified". At the same time,
      Show all
    • Element. When you click the "simplified" link, its content changes to "more". At the same time,
        Only the last element is displayed.
      • Five elements, including.

Core point: He didn't tell which ones to hide

  • So I want to list eight
  • Elements, points simplify random hiding of the first seven
  • Three of the elements.

    Ideas:

    ① From 0 ~ Generate three random numbers in Step 6.

    ② Determine whether the three random numbers are equal. If they are not equal, perform the hidden operation.

    ③ If a random number already exists, re-execute the function.

    Implementation: Generate 0 ~ A Random Number of 6

    The Code is as follows:

    Var ran1 = parseInt (Math. random () * 7); // Math. random () generates a random number [)


    Complete code:

          
          
  • 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.