本文介绍了如何将在daterangepicker中选择的日期范围传递给变量或返回到javascript中的输入文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的下面的JavaScript使用DateRangePicker的预设范围-我需要将选定的开始日期和结束日期传递给两个名为StartDate和EndDate的变量,或者将其传递回我的LogiXML输入文本框.我不确定该怎么做.请帮忙.

My javascript below using preset ranges for DateRangePicker -I need to pass the selected start and end dates to two variables call StartDate and EndDate or pass it back to my LogiXML input text box. I am not sure how to do this. Please help.

注意:我不想为两个不同的输入字段(从和到)运行daterangepicker逻辑.我想使用一个输入字段,但是开始日期和结束日期传递给两个单独的变量.

Note: I don't want to run the daterangepicker logic for two different input fields(from and to). I want to use one input field but the start and end dates are passed to two separate variables.

我正在使用comiseo.daterangepicker,请帮助我.

I am using comiseo.daterangepicker please help me.

$(document).ready(function() {
                    $("#inpDatePicker").daterangepicker({
                        presetRanges: [{
                            text: 'Today',
                            dateStart: function() { return moment() },
                            dateEnd: function() { return moment() }
                        }, {
                            text: 'Month to Date',
                            dateStart: function() { return moment().startOf('month')  },
                            dateEnd: function() { return moment() }
                        }, {
                            text: 'Quarter to Date',
                            dateStart: function() { return moment().startOf('quarter') },
                            dateEnd: function() { return moment() }
                        }, {
                            text: 'Year to Date',
                            dateStart: function() { return moment().startOf('Year') },
                            dateEnd: function() { return moment() }
                        }],
                        applyOnMenuSelect: true,
                        datepickerOptions: {
                            minDate: 0,
                            maxDate: null,
                            numberOfMonths : 3,
                            changeMonth: true,
                            changeYear: true

                        }
                    })
                });

推荐答案

JQuery声明:

$("#inpDatePicker").daterangepicker({...})

事件触发器(触发事件后进入):

Event Trigger (This goes in after an event is fired):

var range = $("#inpDatePicker").daterangepicker("getRange");
$("#range_start").val(range['start']);
$("#range_end").val(range['end']);

HTML:

<input id="inpDatePicker" name="inpDatePicker" type="text">
<input type="hidden" name="range_start" id="range_start">
<input type="hidden" name="range_end" id="range_end">

这篇关于如何将在daterangepicker中选择的日期范围传递给变量或返回到javascript中的输入文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 06:12