5.0 SpringBoot普通上傳功能 > 我的程式猿之路:第四十章
阿新 • • 發佈:2018-12-31
1 <!DOCTYPE html>
2 <html lang="en" xmlns:th="http://www.thymeleaf.org">
3 <head>
4 <meta charset="UTF-8">
5 <title>Upload Page</title>
6 </head>
7
8 <body>
9 <form action="/index.do/upload" method="post" enctype="multipart/form-data">
10 <table>
11 <tr>
12 <td><input type="file" id="fileNameEmg" name="fileNameEmg"></td><h2 th:text="${emg}"/>
13 <td th:if="${emg=='上傳成功!'}"><img th:src="@{'/img/'+${image}}" alt="picture" width="100px" height="100px" /></td>
14 </tr>
15 <tr>
16 <td><input type="button" value="submit" onclick="aa(this)"></td>
17 </tr>
18 </table>
19
20 </form>
21 <script>
22
23 function aa(obj){
24 var fiel = document.getElementById("fileNameEmg ");
25 var a = fiel.value;
26 if(a.indexOf(".png")!=-1||a.indexOf(".jpg")!=-1){
27
28 obj.form.submit()
29 }else{
30 alert("請選擇圖片檔案")
31 }
32 }
33 </script>
34 </body>
35 </html>