Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/449.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript-使用自定义按钮将日期选择器设置为特定日期_Javascript_Jquery - Fatal编程技术网

Javascript-使用自定义按钮将日期选择器设置为特定日期

Javascript-使用自定义按钮将日期选择器设置为特定日期,javascript,jquery,Javascript,Jquery,因此,我能够添加自定义按钮的日期选择器。我想添加的是季度按钮,所以是Q1、Q2、Q3和Q4 我搞不懂的是,当按下其中一个按钮时,如何设置一个特定的日期 例如,当按Q1时,它会将日期设置为3月31日。 现在我只想把它设置为当前年份,我会添加一个年份下拉列表或稍后的内容 我尝试了以下方法,但不起作用: $( "<button>", { text: "Q4", click: function(event) { var inst = $.datepi

因此,我能够添加自定义按钮的日期选择器。我想添加的是季度按钮,所以是Q1、Q2、Q3和Q4

我搞不懂的是,当按下其中一个按钮时,如何设置一个特定的日期

例如,当按Q1时,它会将日期设置为3月31日。 现在我只想把它设置为当前年份,我会添加一个年份下拉列表或稍后的内容

我尝试了以下方法,但不起作用:

$( "<button>", {
    text: "Q4",
    click: function(event) 
    {
        var inst = $.datepicker._curInst;
        var newDate = new Date();
        inst.selectedDay = inst.currentDay = newDate.getDate();
        inst.drawMonth = inst.selectedMonth = inst.currentMonth = newDate.getMonth();
        inst.drawYear = inst.selectedYear = inst.currentYear = newDate.getFullYear();
        //Code to clear your date field (text box, read only field etc.) I had to remove the line below and add custom code here
        $.datepicker._selectDate(event.target, $.datepicker._formatDate(inst, inst.currentDay, inst.currentMonth, inst.currentYear));
    }
}).appendTo( quarterContainer )
$(“”{
正文:“第四季度”,
单击:功能(事件)
{
var inst=$.datepicker.\u curInst;
var newDate=新日期();
inst.selectedDay=inst.currentDay=newDate.getDate();
inst.drawMonth=inst.selectedMonth=inst.currentMonth=newDate.getMonth();
inst.drawYear=inst.selectedYear=inst.currentYear=newDate.getFullYear();
//要清除日期字段(文本框、只读字段等),我必须删除下面的行,并在此处添加自定义代码
$.datepicker.\u选择日期(event.target,$.datepicker.\u格式日期(inst,inst.currentDay,inst.currentMonth,inst.currentYear));
}
}).附件(四分之一集装箱)

在本例中,我只是设置当前日期,但当我开始工作时,我将传入一个日期

我认为这应该行得通,不过谷歌很容易做到:)


您是否尝试过$(“#dateselector”).datepicker(“setDate”,新日期(2008,9,03));是的,这很有效。谢谢有一个轻微的调整。我从未在上面提到过它,但在实例化datepicker时,我的代码在beforeShow中。因此,我没有使用$('#datepicker'),而是使用$(input),其中input是传递到beforeShow函数的参数。
$('#Q1').click(function(){
    $('#datepicker').datepicker("setDate", new Date(2018,31,03) );
})