How do I set the first day and weeks for Bootstrap Datepicker

心已入冬 提交于 2019-12-30 05:47:09

问题


I'm new to this: I'm playing with Bootstrap Datepicker and have got it to work with

$(document).ready(function () {
  $('#datepickeron').datepicker()
});

And then a

<div id="dateoickeron"></div>

But I can't set first day or weeks like in jQuery UI. Normally I can use firstDay: 1, weekHeader: "Uge", showWeek: true like in jQuery UI and show 3 months like numberOfMonths: [3, 1], stepMonths: 3.

How do I do this for the Bootstrap Datepicker?


回答1:


Try adding weekStart . Visit here for more details about it

$(document).ready(function () {
 $('#datepickeron').datepicker({
   weekStart: 0 // day of the week start. 0 for Sunday - 6 for Saturday
 });
});



回答2:


Some example. Hope it helps. AS usual goes inside $(document).ready(function(){});

$('#fromDate').datepicker('setStartDate', '-15d');
$('#fromDate').datepicker('setEndDate', '1d');
$('#toDate').datepicker('setStartDate', '-15d');
$('#toDate').datepicker('setEndDate', '1d');


    // Initialize the dates
$('#cv-rpt-sdate').datepicker({format: 'dd-mm-yyyy',"autoclose": true});
$('#cv-rpt-edate').datepicker({format: 'dd-mm-yyyy',"autoclose": true});
$('#cv-rpt-sdate').datepicker('setEndDate', '1d');
$('#cv-rpt-edate').datepicker('setEndDate', '1d');

$('#dboard-att-date').datepicker({format: 'dd-mm-yyyy',"autoclose": true});
$('#dboard-att-date').datepicker('setStartDate', '-7d');
$('#dboard-att-date').datepicker('setEndDate', '1d');



回答3:


No need of jquery or javascript-

You can set this property in Tag itself.

property -   data-date-week-start   
type  -    integer  
default  -    0 
description - day of the week start. 0 for Sunday - 6 for Saturday

For Example- I have set to start from Monday, then data-date-week-start="1"

<div class="input-append date" id="dp3" data-date="12-02-2012" data-date-format="dd-mm-yyyy" data-date-week-start="1">
  <input class="span2" size="16" type="text" value="12-02-2012">
  <span class="add-on"><i class="icon-th"></i></span>
</div>



回答4:


Did you notice there's a typo in your 'id' element? Misspelled "datepickeron" as "dateoickeron." My apologies in advance for not simply adding this in a comment, but I haven't earned permission to do so yet.

<div id="dateoickeron"></div>

...should be:

<div id="datepickeron"></div>



来源:https://stackoverflow.com/questions/12143526/how-do-i-set-the-first-day-and-weeks-for-bootstrap-datepicker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!