<!DOCTYPE html>
<html>
<body>
生日(年月):<input type="month" id="myMonth" name="bdaymonth">
<p>单击按钮可显示和/或更改月份字段的 name 属性的值。</p>
<button onclick="display()">显示名称</button>
<button onclick="change()">修改名称</button>
<p><b>注意:</b>type="month" 的输入元素在 Firefox 中不会显示为任何日期字段/日历。</p>
<script>
function display() {
var x = document.getElementById("myMonth").name;
alert("月份字段的名称是:" + x);
}
function change() {
var x = document.getElementById("myMonth").name = "newMonthName";
alert ("名称更改为:" + x);
}
</script>
</body>
</html>