BootStrap的日历插件的使用

  • Post author:
  • Post category:其他


BootStrap的日期插件的使用:

加载Bootstrap-datetimepicker插件的js.

HTML中:<input type=”text” value=”2012-05-15 21:05″ id=”datetimepicker”>

JS中:$(‘#datetimepicker’).datetimepicker({



format: ‘yyyy-mm-dd hh:ii’



});

类似案例:

HTML:

<div id=”date-from-picker” class=”input-group date datepicker”>

<input type=”text” name=”date_from”

class=”form-control” readonly=”readonly”

value=”{

{ array_get($search, ‘date_from’) }}” />

<span class=”input-group-addon”><i class=”glyphicon glyphicon-remove”></i></span>

<span class=”input-group-addon”><i class=”glyphicon glyphicon-calendar”></i></span>

</div>

JS:

requirejs([‘../config’], function () {

require([‘jquery’, ‘bootstrap’, ‘datetimepicker-locale-zh-CN’], function ($) {

var dateFromPicker = $(‘#date-from-picker’),

dateFromInput = dateFromPicker.find(‘input’),

dateToPicker = $(‘#date-to-picker’),

dateToInput = dateToPicker.find(‘input’);

dateFromPicker.datetimepicker({

format: ‘yyyy-mm-dd’,

autoclose: true,

todayBtn: true,

minuteStep: 5,

language: ‘zh-CN’,

minView: ‘month’

});

dateToPicker.datetimepicker({

format: ‘yyyy-mm-dd’,

autoclose: true,

todayBtn: true,

minuteStep: 5,

language: ‘zh-CN’,

minView: ‘month’

});

dateFromPicker.on(‘changeDate’, function (event) {

var toDate = dateToInput.val(),

date = event.date;

if (date) {

date.setUTCHours(0);

date.setUTCMinutes(0);

date.setUTCSeconds(0);

date.setUTCMilliseconds(0);

}

dateToPicker.datetimepicker(‘setStartDate’, event.date);

if ($.trim(toDate) !== ” && event.date > new Date(toDate)) {

dateToInput.val(”);

dateToPicker.datetimepicker(‘update’);

}

});

dateToPicker.on(‘changeDate’, function (event) {

var fromDate = dateFromInput.val(),

date = event.date || new Date();

if (date) {

date.setUTCHours(0);

date.setUTCMinutes(0);

date.setUTCSeconds(0);

date.setUTCMilliseconds(0);

}

dateFromPicker.datetimepicker(‘setEndDate’, date);

if ($.trim(fromDate) !== ” && date < new Date(fromDate)) {

dateFromInput.val(”);

dateFromPicker.datetimepicker(‘update’);

}

});

});

});



版权声明:本文为qq_14855277原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。