欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JavaScript中的FileReader圖片預(yù)覽上傳功能實現(xiàn)代碼

 更新時間:2017年07月24日 15:52:13   作者:shengmeshi  
本文通過實例代碼給大家介紹了js中的FileReader圖片預(yù)覽上傳功能,代碼分為html和js代碼兩部分,具體實現(xiàn)代碼大家參考下本文

關(guān)于filereader圖片預(yù)覽上傳功能的實現(xiàn)代碼如下所示:

html:

<div style="width:200px;height:200px;">
 <label for="ceshi" style="display:block;">
  <img style="width:200px;height:200px;" id="image" src=""/>
  <input id="ceshi" type="file" onchange="selectImage(this);" hidden/>
 </label>
</div>

js:

 var image = '';
 function selectImage(file){
 if(!file.files || !file.files[0]){
   return;
 }
 var reader = new FileReader();
 reader.onload = function(evt){
  document.getElementById('image').src = evt.target.result;
  image = evt.target.result;
 }
 reader.readAsDataURL(file.files[0]);
 }
 function uploadImage(){
  console.log(image);
  $.ajax({
   type:'POST',
   url: 'ajax/uploadimage', //圖片上傳地址
   data: {image: image},
   async: true,
   dataType: 'json',
   success: function(data){
   if(data.success){
    alert('上傳成功');
   }else{
   alert('上傳失敗');
   }
  },
  error: function(err){
   alert('網(wǎng)絡(luò)故障');
  }
 });
}

引用:<script src="js/jQuery.min.js"></script>

總結(jié)

以上所述是小編給大家介紹的JavaScript中的FileReader圖片預(yù)覽上傳功能實現(xiàn)代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論