bootstrap datepicker今天默认为 [英] bootstrap datepicker today as default

查看:103
本文介绍了bootstrap datepicker今天默认为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这个 bootstrap-datepicker 作为我的日期选择器。我希望日期选择器选择今天作为开始日期或默认日期。
我无法弄清楚如何自动设置今天,所以我做了一个效率低下的方式。

HTML:

 < input type =textvalue =today(); ID = 日期选择器/> 

JS:

  $('#datepicker')。datepicker(); 
函数today(){
var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth()+ 1;
var curr_year = d.getFullYear();
document.write(curr_date + - + curr_month + - + curr_year);

在线示例: http://jsfiddle.net/BXZk2/



只要寻找一个简单的解决方案, TODAY。



谢谢

解决方案

/ p>

$(#datepicker)。datepicker(setDate,new Date());



以及autoclose(小提琴):

  $('#datepicker')。datepicker({
setDate:new Date(),
autoclose :true
});

jQuery> datepicker API


I am using this bootstrap-datepicker for my datepicker. I'd like the datepicker to choose "today" for start day or default day. I cannot figure out how to set "today" automatically, so I did an inefficient way

HTML:

<input type="text" value ="today();" id="datepicker"/>

JS:

 $('#datepicker').datepicker();
function today(){
    var d = new Date();
    var curr_date = d.getDate();
    var curr_month = d.getMonth() + 1;
    var curr_year = d.getFullYear();
    document.write(curr_date + "-" + curr_month + "-" + curr_year);
}

Online Sample: http://jsfiddle.net/BXZk2/

Just looking for an easy solution to make the default day as "TODAY".

Thanks

解决方案

This should work:

$("#datepicker").datepicker("setDate", new Date());

And for autoclose (fiddle):

$('#datepicker').datepicker({
        "setDate": new Date(),
        "autoclose": true
});

jQuery > datepicker API

这篇关于bootstrap datepicker今天默认为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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