HTML 5 - iOS上的输入类型日期格式 [英] HTML 5 - Input type date formatting on iOS
问题描述
我在iPhone上使用HTML 5表单。此表单有一个输入元素,如下所示:
I am using an HTML 5 form on an iPhone. This form has an input element like the following:
<input id="birthdate" type="date" />
当用户点击此字段时,会出现iOS日期选择器。在用户选择日期后,它会将字段中的日期显示为:2012年4月14日。
When a user clicks this field, the iOS date picker appears. After a user selects a date, it puts the date in the field displayed as something like: Apr 14, 2012.
我的问题是,有没有办法格式化这个日期,以便在文本框中看起来像04-14-2012?或者,最好是有直接的方法将iOS日期格式转换为JavaScript Date对象吗?
My question is, is there a way to format this date so that it looks like 04-14-2012 in the text box? Or, preferably, is there an straight forward approach to converting the iOS date format to a JavaScript Date object?
推荐答案
我一直以为格式是 YYYY-MM-DD
。
无论如何,你可以用JavaScript转换它。
Anyway, you could convert it with JavaScript.
var dateInput = document.getElementById('birthdate');
dateInput.addEventListener('change', function() {
dateInput.value = new Date(dateInput.value).toISOString().split('T')[0];
}, false);
这篇关于HTML 5 - iOS上的输入类型日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!