HTML DOM Input FileUpload type 屬性
HTML DOM input FileUpload type 屬性返回 HTML 文件中 <input> 元素的 type 屬性的值。
語法
語法如下 −
object.type
舉例
我們來看看 HTML DOM input 檔案上傳 type 屬性的一個示例 −
<!DOCTYPE html> <html> <head> <style> body{ text-align:center; background-color:#52B2CF; color:#fff; } .btn{ background-color:coral; border:none; height:2rem; border-radius:50px; width:60%; margin:1rem auto; display:block; color:#fff; outline:none; } .show{ font-size:2rem; color:#fff; font-weight:bold; } </style> </head> <body> <h1>DOM fileupload type property example</h1> <input type = "file" class = "file-upload-btn"> <button onclick="getType()" class="btn">Click me to get value of type property</button> <div class="show"></div> <script> function getType() { var fileBtn = document.querySelector(".file-upload-btn"); document.querySelector('.show').innerHTML = fileBtn.type; } </script> </body> </html>
輸出
這將生成以下輸出 −
現在單擊“橙色”按鈕可獲取 input 檔案上傳按鈕的 type 屬性值。
廣告