<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                最近剛開始學習html5,本來應該先寫點關于語義化標簽的內容,鑒于自己對語義化標簽的理解還不算深刻,所以,打算待自己對這部分內容有深刻理解之后,再分享。 file控件和select都是屬于樣式有點不受控制的兩個怪胎,關于如何修改它們的樣式,后面會再作介紹。本篇博客比較基礎,其實就是講file控件,以及fileList對象。 首先我學習起來屬于比較慢的,必須要自己慢慢理解和體會,囫圇吞棗式的學習不太喜歡,因此,每篇博客亦不會分享太多內容,當然,僅是下文提及的一點內容,也花費了我一些時間。 file控件: ~~~ <input type = "file" id = "idName" multiple = "multiple"> document.getElementById("idName").file; //返回的是fileList對象。 ~~~ fileList對象的常用方法有name(文件名稱)、type(文件類型)、size(文件大小)、lastModefiedDate(文件的最后修改時間)等 默認情況下,選擇文件為單選,但是加上multiple屬性之后,即可以多選。 此處的multiple屬性,只寫”multiple”或者是寫成”multiple=’multiple’”這種形式都是可以,這點類似于autofocus,loop這類屬性。個人習慣寫成multiple=’multiple’這種格式。 此外,file控件還有accept屬性,用于指定選擇文件類型。 accept=”application/msexcel” accept=”application/msword” accept=”application/pdf” accept=”application/poscript” accept=”application/rtf” accept=”application/x-zip-compressed” accept=”audio/basic” accept=”audio/x-aiff” accept=”audio/x-mpeg” accept=”audio/x-pn/realaudio” accept=”audio/x-waw” accept=”image/gif” accept=”image/jpeg” accept=”image/tiff” accept=”image/x-ms-bmp” accept=”image/x-photo-cd” accept=”image/x-png” accept=”image/x-portablebitmap” accept=”image/x-portable-greymap” accept=”image/x-portable-pixmap” accept=”image/x-rgb” accept=”text/html” accept=”text/plain” accept=”video/quicktime” accept=”video/x-mpeg2” accept=”video/x-msvideo” 下面的代碼對應三部分內容: 1、文件類型不限,顯示文件的文件名、文件類型、文件大小和文件的最后修改時間 2、限制文件類型為圖片,通過正則表達式的形式,在選擇之后判斷,顯示文件的文件名、文件類型、文件大小和文件的最后修改時間 3、限制文件類型為圖片,通過accept屬性,在選擇文件時限制,顯示文件的文件名、文件類型、文件大小和文件的最后修改時間 代碼如下: **HTML部分:** ~~~ <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="Generator" content="EditPlus?"> <meta name="Author" content="Yvette Lau"> <meta name="Keywords" content="關鍵字"> <meta name="Description" content="描述"> <title>Document</title> <style> *{ margin:0px; padding:0px; font-size:22px; } .content{ background-color:#57FF57; opacity:0.6; padding:40px ; width:600px; border-radius:10px; margin:20px auto; } input[type='file']{ outline:none; } input[type='button']{ border-radius:10px; height:50px; width:80px; background-color:pink; outline:none; cursor:pointer; } input[type='button']:hover{ font-weight:600; } #details, #information, #imgInfo{ border-radius:10px; padding:10px 20px; background-color: rgba(246,255,73,0.6); color:#000000; display:none; margin:10px; -moz-user-select: none; -webkit-user-select: none; -ms-user-select: none; user-select: none; } #details p, #information p, #imgInfo p{ font-weight: 600; font-family: "Microsoft Yahei"; height: 40px; line-height: 40px; } </style> </head> <body> <div class = "content"> <input type = "file" id = "file" multiple = "multiple"/> <input type = "button" id = "upload" value = "上傳"/> <div id = "details"> </div> </div> <div class = "content"> <input type = "file" id = "image" multiple = "multiple" /> <input type = "button" id = "show" value = "上傳"/> <div id = "information"> </div> </div> <div class = "content"> <input type = "file" id = "imageOnly" multiple = "multiple" accept = "image/*"/> <input type = "button" id = "uploadImg" value = "上傳"/> <div id = "imgInfo"> </div> </div> </body> </html> ~~~ JS部分: ~~~ <script type = "text/javascript"> window.onload = function(){ /*文件上傳*/ var filesList = document.getElementById("file"); var up = document.getElementById("upload"); var details = document.getElementById("details"); /*通過正則表達式,限制文件類型*/ var imgList = document.getElementById("image"); var show = document.getElementById("show"); var information = document.getElementById("information"); /*通過file空間的自帶屬性accept來限制文件類型*/ var imageOnly = document.getElementById("imageOnly"); var uploadImg = document.getElementById("uploadImg"); var upoadImg = document.getElementById("imgInfo"); up.onclick = function(){ insertInformation(details, filesList); } show.onclick = function(){ insertInformation(information, imgList, /image\/\w+/); } uploadImg.onclick = function(){ insertInformation(upoadImg, imageOnly); } /*將時間格式化為“yy-mm-dd hh:mm:ss”*/ function FormatDate (strTime) { var date = new Date(strTime); return date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate() +" "+ date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(); } /*des是存放信息的對象,fileMes是file控件, pattern是正則表達式*/ function insertInformation(des, fileMes, pattern){ des.innerHTML = ""; for (var i = 0; i < fileMes.files.length; i++) { var file = fileMes.files[i]; if(pattern == undefined || pattern.test(file.type)){ des.innerHTML += "<p>文件名:" + file.name + "</p>"; des.innerHTML += "<p>文件類型:" + file.type + "</p>"; des.innerHTML += "<p>文件大小:" + file.size + "</p>"; des.innerHTML += "<p>最后修改時間:" + FormatDate(file.lastModifiedDate) + "</p>" + "<br/>"; des.style.display = "block"; }else{ alert(file.name + "的文件類型不正確"); } } } }; </script> ~~~ 相信很多人看英文的時間格式還是會有點不習慣,沒辦法,誰讓咱是中國人呢 所以寫了一個時間格式化的函數,將時間轉變為了”yy-mm-dd hh:mm:ss”形式。 上面代碼的運行效果如下: ![這里寫圖片描述](https://box.kancloud.cn/2016-04-07_570603e712949.jpg "")
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看