一个漂亮的日期和时间jQuery插件,使您能够从基于Bootstrap popover组件的日历弹出窗口中选择波斯语(jalali)日期和/或日期范围。
1.在文档中加载jQuery JavaScript库和其他所需资源。
<!-- Bootstrap 5/4/3 --> <link href="/path/to/bootstrap.min.css" rel="stylesheet"> <script src="/path/to/bootstrap.bundle.min.js"></script> <!-- Required For Bootstrap 4/3 --> <script src="/path/to/jquery.min.js"></script> <!-- Required For Bootstrap 3 --> <script src="/path/to/jalaali.js"></script>
2.在文档中加载MD.BootstrapPersianDateTimePicker插件的JS和CSS文件。
<!-- Bootstrap 5 --> <link rel="stylesheet" href="mds.bs.datetimepicker.style.css"> <script src="mds.bs.datetimepicker.js"></script> <!-- Bootstrap 4/3 --> <link rel="stylesheet" href="jquery.Bootstrap-PersianDateTimePicker.css"> <script src="jquery.Bootstrap-PersianDateTimePicker.js"></script>
3.在您指定的输入字段上初始化日期选择器。
<!-- Bootstrap 5 --> <span id="dp-example" class="input-group-text cursor-pointer">ANY TRIGGER ICON</span> <input type="text" placeholder="Date Picker Text" data-name="dp-example-text" class="form-control"> <input type="text" placeholder="Date Picker Date" data-name="dp-example-date" class="form-control"> <!-- Bootstrap 4/3 --> <div class="input-group-prepend"> <span class="input-group-text cursor-pointer" id="dp-example">ANY TRIGGER ICON</span> </div> <input type="text" id="dp-example-text" class="form-control" placeholder="Persian Calendar Text" aria-label="date1" aria-describedby="date1"> <input type="text" id="dp-example-date" class="form-control" placeholder="Persian Calendar Date" aria-label="date11" aria-describedby="date11">
// Bootstrap 5 const dpInstance = new mds.MdsPersianDateTimePicker(document.getElementById('dp-example'), { targetTextSelector: '[data-name="dp-example-text"]', targetDateSelector: '[data-name="dp-example-date"]', }); // Bootstrap 4/3 $('#dp-example').MdPersianDateTimePicker({ targetTextSelector: '#dp-example-text', targetDateSelector: '#dp-example-date', });
4.具有默认值的完整插件选项。
// switches between English number or Persian number englishNumber: false, // "auto" | "top" | "bottom" | "left" | "right" placement: 'bottom', // trigger event trigger: 'click', // enables time picker enableTimePicker: false, // text selector targetTextSelector: '', // date selector targetDateSelector: '', // enables date range selection toDate: false, fromDate: false, // group ID groupId: '', // disables the date picker disabled: false, // text format // yyyy/MM/dd HH:mm:ss textFormat: '', // date formart // yyyy/MM/dd HH:mm:ss dateFormat: '', // is Gregorian isGregorian: false, // is persian number persianNumber: false. // displays in line inLine: false, // selected date // new Date('2018/9/30') selectedDate: undefined, // selected range date as JavaScript Date object // [new Date('2020/8/5'), new Date('2020/8/15')] selectedRangeDate: [], // Selected date to start calendar from it as JavaScript Date object selectedDateToShow: new Date(), // months to show monthsToShow: [0, 0], // year offset yearOffset: 15, // holidays // [new Date(), new Date(2017, 3, 2)] holiDays: [], // disabled dates disabledDates: [], // disable days disabledDays: [], // special days specialDates: [], // disables days before/after today disableBeforeToday: false, disableAfterToday: false, // disables days before/after date disableBeforeDate: undefined, disableAfterDate: undefined, // enables range selecton rangeSelector: false, rangeSelectorStartDate: undefined, rangeSelectorEndDate: undefined, rangeSelectorMonthsToShow: [0,0], // enables modal mode modalMode: false, // on view change calendarViewOnChange: function(date){ // ... }, // on day click onDayClick: function(event){ // ... },
5.API方法。
// For Bootstrap 5 version // use instance.methodName(); // gets selected date text $('#textbox').MdPersianDateTimePicker('getText'); // gets selected date $('#textbox').MdPersianDateTimePicker('getDate'); // gets date range $('#textbox').MdPersianDateTimePicker('getDateRange'); // sets a new date $('#textbox').MdPersianDateTimePicker('setDate', new Date(2018, 12, 24)); // sets a new date range $('#textbox').MdPersianDateTimePicker('setDateRange', new Date(2018, 11, 30), new Date(2018, 12, 25)); // clears selected date $('#textbox').MdPersianDateTimePicker('clearDate'); // sets persian date $('#textbox').MdPersianDateTimePicker('setDatePersian', {year: 1397, month: 1, day: 1, hour: 0, minute: 0, second: 0}); // hides the date time picker $('#textbox').MdPersianDateTimePicker('hide'); // shows the date time picker $('#textbox').MdPersianDateTimePicker('show'); // toggles the date time picker $('#textbox').MdPersianDateTimePicker('toggle'); // disables the date time picker $('#textbox').MdPersianDateTimePicker('disable'); // enables the date time picker $('#textbox').MdPersianDateTimePicker('enable'); // update position $('#textbox').MdPersianDateTimePicker('updatePosition'); // update selected date text $('#textbox').MdPersianDateTimePicker('updateSelectedDateText'); // dispose date picker $('#textbox').MdPersianDateTimePicker('dispose'); // gets popover instance $('#textbox').MdPersianDateTimePicker('getBsPopoverInstance'); // gets modal instance $('#textbox').MdPersianDateTimePicker('getBsModalInstance'); // updates an option $('#textbox').MdPersianDateTimePicker('updateOptions', option, value); // updates options $('#textbox').MdPersianDateTimePicker('updateOptions', {...}); // gets date picker instance $('#textbox').MdPersianDateTimePicker('getInstance'); // changes type $('#textbox').MdPersianDateTimePicker('changeType', /isGregorian/ true, /* englishNumber */ true); // sets new options $('#textbox').MdPersianDateTimePicker('setOption', 'yearOffset', 5); // destroy $('#textbox').MdPersianDateTimePicker('destroy'); // convert Date To String $('#textbox').MdPersianDateTimePicker('convertDateToString', date: new Date(), isGregorian: false, format: 'yyyy/MM/dd'); // convert Date To Jalali $('#textbox').MdPersianDateTimePicker('convertDateToJalali', new Date());
6.在视图更改时触发一个功能。
$('#textbox').MdPersianDateTimePicker({ calendarViewOnChange: function(selectedDateToShow){ // do something } });
7.点击日期时触发一个函数。
$('#textbox').MdPersianDateTimePicker({ onDayClick: function(event){ // do something } });
2023-02-21
2022-08-13
2021-10-18
2021-10-02
2021-06-03
2021-05-16
2021-05-14
2021-02-27
2021-01-10
2020-09-13
2020-08-16
2020-07-13
2020-07-12
2020-06-24
2020-06-04
2019-10-02
2019-10-02
2019-08-25
2019-07-21
2019-07-14
2019-07-13
2019-06-03
2019-05-26
2019-05-20
2019-05-07
2019-04-13
2018-12-17
2018-11-20
2018-11-18
2018-11-03
2018-10-16
2018-10-10
2018-10-02
2018-09-30
2018-09-15
2018-09-12
2018-09-11
2018-09-10
2018-06-19
2018-03-15
2018-02-19
2018-01-28
2017-09-23
2017-05-13
2017-01-16
2016-10-30
2016-09-23
2016-09-17
2016-08-14
2016-05-21
2016-01-27