This article mainly introduces the method of uploading files using JavaScript without refreshing the page. It uses js+css code to introduce the operation process in detail. Friends who need it can refer to it
Using js to give an upload A solution that does not require refreshing the page when making a file
<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(); //创建表单数据对象 formData.append('file',file); //将文件添加到表单对象中 fetch({ //传输 url:'./', mothod:'POST', body:formData }) .then((d)=>{ console.log('result is',d); alert("上传完毕!") }) }
Achieve such an effect:
Use HTML+CSS to achieve the following effect: Layout, border-width: 5px, grid size is 50px*50px. When hovering, the border turns red, so semantics need to be considered.
table{ border-collapse:collapse; /* 为表格设置合并边框模型 */ margin:50px; text-align:center; /* 设置文字居中 */ } 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>
The above is the detailed content of Introduction to the method of uploading files without refreshing in JavaScript. For more information, please follow other related articles on the PHP Chinese website!