当用户选择开始日期和结束日期时,我希望开始日期显示在其他文本框中

When a user selects startDate and endDate, I want start date to be displayed in other text box

我想 select 来自该字段的开始日期: @Html.EditorFor(model => model.TimePeriod.StartDate, new { htmlAttributes = new { @class = "form-control datepicker", @id="StartDate",@onchange="addDates() " } }) @Html.ValidationMessageFor(model => model.TimePeriod.StartDate, "", new { @class = "text-danger" })

我想在这里自动填充开始日期

<td>
                    @Html.EditorFor(model => model.DailyRegister.Date, new { htmlAttributes = new { @class = "form-control", required = "required", @id = "date1" } })
                    @Html.ValidationMessageFor(model => model.DailyRegister.Date, "", new { @class = "text-danger" })
                    <script>
                            function addDates() {
                            document.getElementById("date1").value = document.getElementById("StartDate");
                        }
                    </script>
                </td>

Running above code gives this result

这可能是个愚蠢的问题,但您是否尝试过获取开始日期字段的

document.getElementById("date1").value = document.getElementById("StartDate").value;

根据调用 addDates() 函数的时间,您可能还需要一个事件侦听器。