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

JavaScript上傳文件時不用刷新頁面方法總結(jié)(推薦)

 更新時間:2017年08月15日 10:37:41   作者:Cynthia_xie  
這篇文章主要介紹了JavaScript上傳文件時不用刷新頁面方法,用js+css代碼詳細(xì)介紹了操作過程,需要的朋友可以參考下

用js給出一個上傳文件時不用刷新頁面的方案

 <input id="upload" type="file"/>
 <button id="upload-btn">upload</button>
 document.getElementById('upload-btn').onclick = function(){ 
  var oInput = document.getElementById('upload'); 
  var file = oInput.files[0];  //選取文件
  var formData = new FormData(); //創(chuàng)建表單數(shù)據(jù)對象
  formData.append('file',file); //將文件添加到表單對象中
  fetch({       //傳輸
   url:'./',
   mothod:'POST',
   body:formData 
  }) 
  .then((d)=>{
  console.log('result is',d);
  alert("上傳完畢!")
  })
 }

實(shí)現(xiàn)這么一個效果:

使用HTML+CSS實(shí)現(xiàn)如圖布局,border-width:5px,格子大小是50px*50px,hover時,邊框變成紅色,需要考慮語義化。

       

 table{
   border-collapse:collapse; /* 為表格設(shè)置合并邊框模型 */
   margin:50px;
   text-align:center; /* 設(shè)置文字居中 */
  } 
  table tr{
   border:none;
  } 
  table.tab td{
   width:50px;
   height:50px;
   border:5px inset blue;
  } 
  table.tab td:hover{
   border:5px solid red;
   cursor: pointer;
  }
  <table class="tab">
  <tr>
   <td>1</td>
   <td>2</td>
   <td>3</td>
  </tr>
  <tr>
   <td>4</td>
   <td>5</td>
   <td>6</td>
  </tr>
  <tr>
   <td>7</td>
   <td>8</td>
   <td>9</td>
  </tr>
  </table>

以上就是無刷新上傳文件的全部內(nèi)容啦,也希望大家繼續(xù)支持腳本之家網(wǎng)站~~~

相關(guān)文章

最新評論