Handle and turn the json data into options selector with jQuery - Javascript jQuery

Javascript examples for jQuery:Json

Description

Handle and turn the json data into options selector with jQuery

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
  <script type="text/javascript">
    $(function(){//  w w  w.ja  v a 2 s .  c om
var data='[2, 4, 6]';
var obj=$.parseJSON(data);
$.each(obj, function(k, v) {
    $("<option />").text(v).val(v).appendTo("#time");
});
    });

      </script> 
 </head> 
 <body> 
  <select id="time"></select>  
 </body>
</html>

Related Tutorials