Advertisement
SvetoslavUzunov

Untitled

May 19th, 2021
1,085
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.09 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.  
  4. <head>
  5.     <meta charset="UTF-8">
  6.     <title>Document</title>
  7.     <link rel="stylesheet" href="https://bootswatch.com/3/flatly/bootstrap.css">
  8.     <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
  9.     <script>
  10.         $(document).ready(function () {
  11.             const getVal = () => {
  12.                 return Number($(".form-control").val());
  13.             }
  14.            
  15.             $(".btn").click(() => {
  16.                 createButtons(getVal());
  17.             })
  18.  
  19.             const createButtons = (n) => {
  20.                 $("inner").empty();
  21.                 for (let i = 0;i < n;i++) {
  22.                     $(".inner").append(`<button href="#button${i}" id="button${i}">Open section ${i}</button>`);
  23.                     $(document).on('click', `#button${i}`, () => {
  24.                         showSection(i);
  25.                     });
  26.                 };
  27.                 showSection(0);
  28.             };
  29.  
  30.             const showSection = (index) => {
  31.                 $("#sectionContainer").empty().append(`<p id="sectionInner">This is section number ${index}</p>`);
  32.                 const genRandom = () => { return Math.floor(Math.random() * 255) + 0 };
  33.                 $("#sectionInner").css('background-color', `rgba(${genRandom()},${genRandom()},${genRandom()})`);
  34.             }
  35.         })
  36.     </script>
  37. </head>
  38.  
  39. <body>
  40.     <div class="container">
  41.         <div class="row">
  42.             <input type="text" class="form-control">
  43.             <input type="submit" class="btn btn-default">
  44.         </div>
  45.         <!-- <div class="row">
  46.             <ul class="nav nav-tabs">
  47.                 <li class="active"><a href="#myid1" data-toggle="tab" aria-expanded="true">1</a></li>
  48.                 <li class=""><a href="#myid1" data-toggle="tab" aria-expanded="false">2</a></li>
  49.                 <li class=""><a href="#myid1" data-toggle="tab" aria-expanded="false">3</a></li>
  50.             </ul>
  51.             <div id="myTabContent" class="tab-content">
  52.                 <div class="tab-pane fade active in" id="myid1">
  53.                     <p>1 текст текст</p>
  54.                 </div>
  55.                 <div class="tab-pane fade" id="myid2">
  56.                     <p>2 текст текст текст текст </p>
  57.                 </div>
  58.                 <div class="tab-pane fade" id="myid3">
  59.                     <p>3 текст текст текст текст текст текст текст текст</p>
  60.                 </div>
  61.             </div>
  62.         </div> -->
  63.         <div class="inner"></div>
  64.         <div id="sectionContainer"></div>
  65.     </div>
  66.  
  67. </body>
  68.  
  69. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement