Thuộc tính disabled của <input type="file"> cho phép trả về hoặc thiết lập trạng thái vô hiệu hóa (không thể chọn tệp). Khi disabled, nút chọn file sẽ mờ đi và không phản hồi.
Cú pháp
Lấy giá trị:
fileInput.disabled
Thiết lập giá trị:
fileInput.disabled = true | false
Ví dụ: Bật/tắt input file
<!DOCTYPE html>
<html>
<head>
<style>
body { background: #397367; color: white; font-family: sans-serif; padding: 20px; text-align: center; }
p { font-size: 1.2rem; }
input { width: 300px; border: none; margin: 10px 0; padding: 8px; }
.btn {
display: block; margin: 15px auto;
background-color: #22223B; color: white; border: none;
height: 40px; border-radius: 25px; font-weight: bold;
padding: 0 20px; cursor: pointer;
}
</style>
</head>
<body>
<h1>Ví dụ FileUpload disabled Property</h1>
<p>Bạn có thể chọn file không?</p>
<input type="file" id="fileInput">
<button onclick="toggleDisabled()" class="btn">Bật/Tắt chọn file</button>
<script>
function toggleDisabled() {
var fileInput = document.getElementById("fileInput");
fileInput.disabled = !fileInput.disabled;
}
</script>
</body>
</html>
Kết quả
Trạng thái bình thường:

Sau khi nhấn "Bật/Tắt chọn file" - input bị disabled (mờ):

💡 Ứng dụng:
- Vô hiệu hóa upload cho đến khi người dùng đồng ý điều khoản.
- Ngăn chọn file mới khi đang upload (kết hợp với AJAX).
- Input disabled **không gửi file** khi submit form thường.