Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.21 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script
  5.  src="https://code.jquery.com/jquery-3.2.1.js"
  6.  integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE="
  7.  crossorigin="anonymous"></script>
  8. <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet" />
  9. <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
  10.     <title></title>
  11. </head>
  12. <body>
  13.  
  14. <input type="submit" id="button" name="">
  15.  
  16.     <script type="text/javascript">
  17.         var data = new Array();
  18.         $(document).ready(function() {
  19.  
  20.             $(".js-example-basic-single").select2();
  21.        
  22.             data.push({id: 1, val: "lol"});
  23.             data.push({id: 2, val: "ПИДОР"});
  24.             data.push({id: 3, val: "УКРАИНА"});
  25.         });
  26.  
  27.         function addToList(id, value){
  28.             $('#list').html($('#list').html() + '<option value="'+value+'">'+value+'</option>');
  29.         }
  30.  
  31.         $(document).on('click', '#button', function(){
  32.             for(var i = 0; i< data.length; i++)
  33.                 addToList(data[i].id, data[i].val);
  34.         });
  35.  
  36.  
  37.     </script>
  38.  
  39.     <select style=" width:  100%;" id="list" class="js-example-basic-single">
  40.       <option value="AL">Alabama</option>
  41.  
  42.       <option value="WY">Wyoming</option>
  43.     </select>
  44. </body>
  45. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement