HTML5 datetime组件不能在浏览器中工作



我编写了简单的html5输入类型" datetime"。

<html>
<head></head>
<body>
    <input type="datetime" width="30px">
</body>
</html>
在IE(Edge)中运行上述代码。输出显示为简单的测试输入。我猜,这个datetime组件在所有浏览器中都被删除了。

正确代码为:(将datetime替换为date)

<html>
 <head></head>
 <body>
   <input type="date" width="30px">
 </body>
</html>

它可以很好地使用Edge, chrome等

目前你可以考虑使用输入类型datetime-local:这只适用于edge和chrome,但不是在所有浏览器

可以考虑另一种方法:jquery ui插件或bootstrap,根据哪种方法适合您。

你可以像下面这样使用jQuery-Timepicker-Addon:

$('#basic_example_3').datetimepicker({
  timeFormat: "hh:mm tt"
});
<link href="https://code.jquery.com/ui/1.12.0/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<link rel="stylesheet" href="https://rawgit.com/trentrichardson/jQuery-Timepicker-Addon/master/dist/jquery-ui-timepicker-addon.min.css">
<script src="https://rawgit.com/trentrichardson/jQuery-Timepicker-Addon/master/dist/jquery-ui-timepicker-addon.min.js"></script>
<input id="basic_example_3" type="text">

如果可以使用boostrap,则可以使用bootstrap-datetimepicker,如以下代码片段所示:

$('#appointment_end_datetime').datetimepicker({
  format: "Y-M-d H:mm",
  sideBySide: true
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.42/css/bootstrap-datetimepicker.css">
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.14.1/moment.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.42/js/bootstrap-datetimepicker.min.js"></script>
<div class="container">
    <div class="row">
        <div class='col-sm-6'>
            <div class="form-group">
                <div class='input-group date' id='appointment_end_datetime'>
                    <input type='text' class="form-control" />
                    <span class="input-group-addon">
                        <span class="glyphicon glyphicon-calendar"></span>
                    </span>
                </div>
            </div>
        </div>
    </div>
</div>

相关内容

最新更新