HTML5 type=file檔案上傳功能執行個體詳解

來源:互聯網
上載者:User
本文主要和大家介紹HTML5新特性之type=file檔案上傳功能,需要的朋友可以參考下,希望能協助到大家。

1、文法

<input name="myFile" type="file">

2、屬性(以下三個僅HTML5支援,因此存在相容性問題)

(1)multiple :表示使用者是否可以選擇多個值。multiple只能用於type=file和type=email。

(2)accept:伺服器接受的檔案類型,否則將被忽略。

音頻/ *代表音效檔。僅HTML5支援
視頻/ *代表視頻檔案。僅HTML5支援
映像/ *表示影像檔。僅HTML5支援

(3)required:此屬性指定使用者在提交表單之前必須填寫一個值。

3、擷取上傳的檔案資訊

<!DOCTYPE html><html lang="zh">    <head>        <meta charset="UTF-8" />        <meta http-equiv="X-UA-Compatible" content="ie=edge" />        <title>file multiple</title>    </head>    <body>        <input type="file" multiple="multiple" id="test">        <p id='content'></p>        <script type="text/javascript">            var test = document.getElementById('test');            test.addEventListener('change', function() {                var t_files = this.files;                var str = '';                for(var i = 0, len = t_files.length; i < len; i++) {                    console.log(t_files[i]);                    str += '<a href="javascript:void(0)">' + t_files[i].name + '</a><br/>';                };                document.getElementById('content').innerHTML = str;            }, false);        </script>    </body></html>

顯示:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.