คุณสมบัติประเภท FileUpload อินพุต HTML DOM ส่งคืนค่าแอตทริบิวต์ประเภท องค์ประกอบในเอกสาร HTML
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์ -
object.type
ตัวอย่าง
ให้เราดูตัวอย่างของคุณสมบัติประเภทการอัปโหลดไฟล์อินพุต HTML DOM -
<!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> ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -

ตอนนี้คลิกที่ “สีส้ม ” เพื่อรับค่าคุณสมบัติประเภทปุ่มอัพโหลดไฟล์อินพุต
