此处以上传图片为例:

html文件:

 1 <html lang="en">
 2     <meta charset="UTF-8">
 3     <title>上传图片</title>
 4     <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
 5     <style>
 6         #w1 img{
 7             width: 350px;
 8             height: auto;
 9             margin: 10px;
10         }
11     </style>
12 <body>
13 <form method="post" action="d.php" enctype="multipart/form-data">
14     <input name='uploads[]' type="file" multiple onchange="tu(this)">
15     <input type="submit" name="uploadpic" value="上传">
16 </form>
17 <div id="w1"></div>
18 </body>
19 <script>
20     function tu(dom){
21         var url = dom.files;
22         //var path = window.URL.createObjectURL(dom.files[0]);
23         //var path1 = window.URL.createObjectURL(dom.files[1]);
24         $.each(url, function(i){
25             var path = window.URL.createObjectURL(url[i]);
26             $('#w1').append("<img src='"+ path +"'>");
27         });
28         //$('#w1').html("<img src='"+ path +"'>");
29         // $('#w2').html("<img src='"+ path1 +"'>");
30         //alert(path);
31     }
32 </script>
33 </html>
html表单部分

相关文章: