bootstrap datetimepicker的时间变成1899年
2014-11-25 09:40
337 查看
bootstrap datetimepicker 重新加载后,日期会变1899年,
这个问题要怎么解决呢??
先看个小例子:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="DateTimePickQuestion1.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<!-- 新 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css">
<!-- 可选的Bootstrap主题文件(一般不用引入) -->
<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap-theme.min.css">
<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="http://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<!-- import datetimepicker js and css -->
<script src="js/bootstrap-datetimepicker.js" type="text/javascript"></script>
<script src="js/locales/bootstrap-datetimepicker.zh-CN.js" type="text/javascript"></script>
<link href="css/bootstrap-datetimepicker.css" rel="stylesheet" type="text/css" />
<!-- my script -->
<script type="text/javascript">
$(function () {
$("#mySelect").change(function () {
$(".form_datetime").datetimepicker('remove');
var type = $("#mySelect").val();
switch (type) {
case "month":
$('.form_datetime').datetimepicker({
autoclose: true,
startView: 'year',
minView: 'year',
format: 'yyyy-mm'
});
break;
case "year":
$('.form_datetime').datetimepicker({
autoclose: true,
startView: 'decade',
minView: 'decade',
format: 'yyyy'
});
break;
} //end switch
})//end change
})//end ready
</script>
</head>
<body>
<div>
<select id='mySelect'>
<option value='year'>year</option>
<option value='month'>month</option>
</select>
<div class="input-group date form_datetime col-md-2" data-date='2014-1-1'>
<input class="form-control" type="text" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-th"></span>
</span>
</div>
</div>
</body>
</html>
上面的小例子就是用 select 标签重新加载不同的datetimepicker
问题就出现在 datetimepicker remove之后,他的时间就变成了 1899年
如图:
要怎么解决这个问题呢?
这里给出一个小小的办法:
就是在你remove datetimepicker之后
使用一下datetimepicker 的 update方法
代码如下:
$("#mySelect").change(function () {
$(".form_datetime").datetimepicker('remove');
var type = $("#mySelect").val();
switch (type) {
case "month":
$('.form_datetime').datetimepicker({
autoclose: true,
startView: 'year',
minView: 'year',
format: 'yyyy-mm'
});
$('.form_datetime').datetimepicker('update', new Date());
break;
case "year":
$('.form_datetime').datetimepicker({
autoclose: true,
startView: 'decade',
minView: 'decade',
format: 'yyyy'
});
$('.form_datetime').datetimepicker('update', new Date());
break;
} //end switch
})//end change
用了update -->new Date() 之后就可以回到今天了!!!
另外想提醒的是:
datetimepicker的startDate属性指的是:
The earliest date that may be selected; all earlier dates will be disabled.
最小的选择时间,比这个最小选择时间小的日期无法选择
最后想说的是 bootstrap datetimepicker 的网站是https://github.com/smalot/bootstrap-datetimepicker
里面有很多说明的,自己看把
这个问题要怎么解决呢??
先看个小例子:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="DateTimePickQuestion1.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<!-- 新 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css">
<!-- 可选的Bootstrap主题文件(一般不用引入) -->
<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap-theme.min.css">
<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="http://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<!-- import datetimepicker js and css -->
<script src="js/bootstrap-datetimepicker.js" type="text/javascript"></script>
<script src="js/locales/bootstrap-datetimepicker.zh-CN.js" type="text/javascript"></script>
<link href="css/bootstrap-datetimepicker.css" rel="stylesheet" type="text/css" />
<!-- my script -->
<script type="text/javascript">
$(function () {
$("#mySelect").change(function () {
$(".form_datetime").datetimepicker('remove');
var type = $("#mySelect").val();
switch (type) {
case "month":
$('.form_datetime').datetimepicker({
autoclose: true,
startView: 'year',
minView: 'year',
format: 'yyyy-mm'
});
break;
case "year":
$('.form_datetime').datetimepicker({
autoclose: true,
startView: 'decade',
minView: 'decade',
format: 'yyyy'
});
break;
} //end switch
})//end change
})//end ready
</script>
</head>
<body>
<div>
<select id='mySelect'>
<option value='year'>year</option>
<option value='month'>month</option>
</select>
<div class="input-group date form_datetime col-md-2" data-date='2014-1-1'>
<input class="form-control" type="text" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-th"></span>
</span>
</div>
</div>
</body>
</html>
上面的小例子就是用 select 标签重新加载不同的datetimepicker
问题就出现在 datetimepicker remove之后,他的时间就变成了 1899年
如图:
要怎么解决这个问题呢?
这里给出一个小小的办法:
就是在你remove datetimepicker之后
使用一下datetimepicker 的 update方法
代码如下:
$("#mySelect").change(function () {
$(".form_datetime").datetimepicker('remove');
var type = $("#mySelect").val();
switch (type) {
case "month":
$('.form_datetime').datetimepicker({
autoclose: true,
startView: 'year',
minView: 'year',
format: 'yyyy-mm'
});
$('.form_datetime').datetimepicker('update', new Date());
break;
case "year":
$('.form_datetime').datetimepicker({
autoclose: true,
startView: 'decade',
minView: 'decade',
format: 'yyyy'
});
$('.form_datetime').datetimepicker('update', new Date());
break;
} //end switch
})//end change
用了update -->new Date() 之后就可以回到今天了!!!
另外想提醒的是:
datetimepicker的startDate属性指的是:
The earliest date that may be selected; all earlier dates will be disabled.
最小的选择时间,比这个最小选择时间小的日期无法选择
最后想说的是 bootstrap datetimepicker 的网站是https://github.com/smalot/bootstrap-datetimepicker
里面有很多说明的,自己看把
相关文章推荐
- bootstrap datetimepicker的时间变成1899年
- bootstrap-datetimepicker出现时间选择时年份显示1899年的异常
- bootstrap-datetimepicker年视图中endDate设置之后比正常时间提前两个月
- bootstrap时间控件随滚动条一起移动bootstrap-datetimepicker.js
- bootstrap datetimepicker 插件怎样获取时间值
- bootstrap:时间选择器datetimepicker调用
- 时间插件-bootstrap-datetimepicker2.3.11
- bootstrap datetimepicker时间日期控件
- Bootstrap3 日期+时间选择控件 datetimepicker的使用方法说明
- bootstrap datetimepicker 时间控件的使用
- BootStrap 时间控件 bootstrap-datetimepicker 火狐浏览器报错m is undefined
- bootstrap datetimepicker2.3.11时间插件使用
- bootstrap中datetimepicker时间插件使用
- bootstrap-datetimepicker 时间日期插件
- Bootstrap 3时间控件datetimepicker的时区及多语言问题
- Bootstrap日期和时间表单组件datetimepicker的使用
- bootstrap-datetimepicker 开始时间与结束时间互相约束
- Bootstrap时间控件 datetimepicker
- datetimepicker bootstrap的时间插件显示位置问题及其他配置