asimryu

korea.html with photo preview -1

Nov 29th, 2017
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.76 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>Document</title>
  6.     <link rel="stylesheet" href="css/bootstrap.css">
  7.     <script src="js/jquery-3.2.1.min.js"></script>
  8. </head>
  9. <body>
  10.     <div class="container">
  11.         <div class="row">
  12.             <div class="col-md-6">
  13.                 <div id="map"></div>
  14.             </div>
  15.             <div class="col-md-6">
  16.                 <h1 id="name_ko"></h1>
  17.                 <h2 id="name_en"></h2>
  18.                 <h3 id="name_full"></h3>
  19.                 <p id="area"></p>
  20.                 <p id="population"></p>
  21.                 <p id="info"></p>
  22.                 <form id="imgform" onsubmit="return false" style="display:none;">
  23.                     <input type="hidden" id="cid">
  24.                     <input type="file" id="photo" class="form-control">
  25.                     <img src="" id="preview" alt="미리보기">
  26.                 </form>
  27.             </div>
  28.         </div>
  29.     </div>
  30.    
  31.     <script>
  32.         var data = [];
  33.         $.getJSON("korea.json",function(json){
  34.             data = json.korea.city;
  35.         });
  36.         $("#map").load("korea.svg");
  37.         $("#map").on("click",".land",function(){
  38.             var id=$(this).attr("id");
  39.             var info = data.filter(function(v){
  40.                 return v.id === id;
  41.             });
  42.             if( info ) {
  43.                 var city = info[0];
  44.                 $("#name_ko").text(city.name_ko);
  45.                 $("#name_en").text(city.name_en);
  46.                 $("#name_full").text(city.name_full);
  47.                 $("#area").text(city.area);
  48.                 $("#population").text(city.population);
  49.                 $("#info").text(city.info);
  50.                 $("#cid").val(city.id);
  51.                 $("#preview").attr("src","");
  52.                 $("#imgform").show();
  53.             }
  54.         });
  55.  
  56.         $("#photo").change(function(){
  57.             previewPhoto(this);
  58.         });
  59.  
  60.         function previewPhoto(input) {
  61.             if( ! input.files ) return;
  62.             if( ! input.files[0] ) return;
  63.             var reader = new FileReader();
  64.             reader.onload = function(e){
  65.                 $("#preview").attr("src",e.target.result);
  66.             };
  67.             reader.readAsDataURL(input.files[0]);
  68.         }
  69.  
  70.     </script>
  71. </body>
  72. </html>
Advertisement
Add Comment
Please, Sign In to add comment