有什么方法可以更改 HTML5 type="date" 以使用像“2015 年 2 月 2 日”这样的格式吗?

Is there any way to change HTML5 type="date" to use format like this "2 February 2015"?

我需要使用 get 方法发送变量,但是日期格式应该是 "dd-monthName-YYYY",例如“02-February-2015”。

Can it be done using HTML5 type="date"?

如果不能,我该怎么做?

你可以这样做:

<html>
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>

    <input id="datefield" type="date" />

    <script>
        var monthNames = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];

        $("#datefield").change(function () {
            var val = $(this).val();
            console.log(val);
            var d = new Date(val);
            console.log(d.getDate() + '-' + monthNames[d.getMonth()] + '-' + d.getFullYear());
        });
    </script>

</html>

结果:

2015-02-02
2-February-2015