使用jQuery设置Bootstrap日期字段输入值 [英] Bootstrap date field input value set using jquery

查看:62
本文介绍了使用jQuery设置Bootstrap日期字段输入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的引导程序输入字段,

This is my bootstrap input field,

<input class="form-control" id="date" required="required" name="date" type="date">

我想在某些事件之后使用jquery设置日期字段值,

I want to set date field value after some event using jquery,

// this is a date string return from database
var data = 2019-05-06 00:00:00 ;
$('#date').val(data);

但未在引导日期选择器中设置该值.

but it's not set the value in bootstrap date picker.

推荐答案

您可以使用 datepicker

使用给定的参数或当前输入值更新日期选择器.参数可以是字符串数组,也可以是Date数组对象,多个字符串或多个Date对象.如果日期提供了参数,它们是Date对象,假定为本地"日期对象,并将其转换为UTC以供内部使用.

Update the datepicker with given arguments or the current input value. The arguments can be either an array of strings, an array of Date objects, multiples strings or multiples Date objects. If date arguments are provided and they are Date objects, it is assumed to be "local" Date objects, and will be converted to UTC for internal use.

示例:

var data = "2019-05-06 00:00:00";
//data is a string
$(".datepicker").datepicker("update", data);


更新设置日期类型html


UPDATE Setting up a date type html

var data = "2019-05-06 00:00:00";
document.getElementById("date").valueAsDate = new Date(data);

<input class="form-control" id="date" required="required" name="date" type="date">

这篇关于使用jQuery设置Bootstrap日期字段输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆