Thuộc tính name của <input type="month"> trả về hoặc thiết lập tên trường form. Dùng để nhận diện giá trị khi submit form (VD: $_POST['thang']).
Cú pháp
Lấy giá trị:
monthInput.name
Thiết lập giá trị:
monthInput.name = "ten_moi"
Ví dụ: Hiển thị name của input month
<!DOCTYPE html>
<html>
<head>
<style>
html, body { height: 100%; margin: 0; font-family: sans-serif; }
body {
text-align: center; color: white;
background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) center/cover no-repeat;
}
input[type="month"] {
width: 35%; border: 2px solid white; background: transparent;
color: white; font-weight: bold; padding: 8px; margin: 10px auto; display: block;
}
.btn {
background: #0197F6; border: none; color: white;
padding: 10px 20px; border-radius: 4px; width: 35%;
margin: 20px auto; display: block; cursor: pointer;
}
.show { font-size: 1.5rem; font-weight: bold; margin-top: 15px; }
</style>
</head>
<body>
<h1>Ví dụ Input Month name Property</h1>
<input type="month" class="monthInput" value="2019-02" name="Truong_Thang_Cua_Toi">
<p>Bạn muốn xem tên của tôi?</p>
<p>Nhấn nút bên dưới</p>
<button onclick="showName()" class="btn">Hiện Name</button>
<div id="result" class="show"></div>
<script>
function showName() {
var input = document.querySelector(".monthInput");
document.getElementById("result").textContent = input.name;
}
</script>
</body>
</html>
Kết quả
Trước khi nhấn:

Sau khi nhấn "Hiện Name":

ℹ️ Lưu ý: Input
type="month" cho phép chọn tháng/năm (định dạng YYYY-MM). Hỗ trợ tốt trên Chrome/Edge/Opera, Firefox/Safari có thể hiển thị dạng text fallback.