有没有办法在 html 表单中将表单域显示为 mm/yyyy?

Is there a way to display the form field as mm/yyyy in html form?

我正在尝试使用 mm/yyyy 作为输入的表单域。你能帮我推荐一种使用这种日期格式的方法吗?

在您的 html 代码中使用输入元素并为其指定“月份”类型 (YYYY-MM)

<input type="month" id="something" />

要获取日期和年份,您可以使用javascript

var date = document.getElementById("something").value

<label for="birthdayMonth">Enter Birthday month-year:</label> <input type="month" id="birthdayMonth" name="birthdayMonth"> 试试这个:

尝试在您的表单中使用以下代码。它应该允许您先输入月份然后输入后一年。

<label for="start">Date:</label>
<input type="month" id="start">

你可以试试这段代码看看

<p id="time"></p>

<script>

    const now = new Date();
    const year = now.getFullYear();
    let month = now.getMonth() + 1;
    if (month < 10) 
        month = '0' + month;
    const time = month + '/' + year;
    document.getElementById("time").innerHTML = time;

</script>

您可以像这样为 html 输入字段尝试这种模式:

<form>
<input type="text" pattern="[0-1]{1}[0-9]{1}/[0-9]{4}">
</form>

除非匹配“MM/YYYY”模式,否则它不会接受任何内容。