HTML日期控件未显示传入值问题求助
Hey there! Let's break down why your date input is acting up in Edge but working fine in IE. The root of the problem comes down to how modern browsers handle date input formats compared to the more lenient older IE.
What's Causing the Problem?
Modern Chromium-based Edge strictly follows the HTML standard for native <input type="date"> controls: the value attribute must be in ISO 8601 format (yyyy-MM-dd). Your current output is 12/4/2020 (mm/dd/yyyy), which Edge doesn't recognize—so it defaults to showing the placeholder instead of your intended date. IE, being an older browser, was more flexible with date formats, which is why it worked there.
Step-by-Step Fix
You need to adjust your ASP code to output the date in the ISO 8601 format. Here's a reliable way to do that:
<% ' Assume your incoming date value is stored in a variable called incomingDate Dim isoFormattedDate ' Build the ISO date string manually to ensure consistent formatting isoFormattedDate = Year(incomingDate) & "-" & _ Right("0" & Month(incomingDate), 2) & "-" & _ Right("0" & Day(incomingDate), 2) %> <!-- Use the formatted date in your input control --> <input type="date" value="<%= isoFormattedDate %>">
This code converts a date like 12/4/2020 to 2020-12-04—a format Edge (and all other modern browsers) will correctly parse and display in the date picker.
Extra Tips
- Eliminate Ambiguity: Using ISO format also removes confusion between date conventions (e.g., is
12/4/2020December 4th or April 12th?), which helps both frontend display and backend SQL Server insertion. - Custom Date Pickers?: If you're using a third-party date control (not the native HTML one), check its docs for a
formatsetting—make sure it matches the format you're passing from ASP.
内容的提问来源于stack exchange,提问作者Dustin Duckworth

