easyui Datebox setValue 与 ie浏览器冲突

我们做的是与医疗有关的项目,所以需要兼容ie浏览器。项目做好后,在ie浏览器测试的时候,发现给easyui时间控件赋值的时候无法赋值正确的时间。而且回显的时间是当前的时间。

我写的代码如下:

//  row.start_time 是从后台返回的时间
$('#datefrom').datebox('setValue', row.start_time);

后来看文档发现 easyui 的日期框(datebox)是把可编辑的文本框和下拉日历面板结合起来的,所以直接传字符串 easyui 就可以帮你自动转换为有效日期。

所以我改了下我的代码

// 从数据库中返回的数据类型为 date 时间类型,数据格式为  2019-07-01 00:00:00
var startTime = row.start_time;
if (startTime) {
	// 格式为 2019-07-01 00:00:00 时,因为没有更改easyui 默认的formatter,所以只需要 2019-07-01 就行
	startTime = startTime.split(" ")[0];
}
$('#datefrom').datebox('setValue', startTime);

更改后,你就会发现在ie浏览器中也可以正确的显示时间了。

你可能感兴趣的:(js)