jQuery datetimepicker-如何在JavaScript中获取日期? [英] jQuery datetimepicker - how to get date in javascript?

查看:816
本文介绍了jQuery datetimepicker-如何在JavaScript中获取日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我在文本输入上附加了jQuery DateTimePicker v2.4.1.我想这样做,然后在用户单击并更改选择器的月份或年份时-它将更新表单中的日期,因为这似乎不是插件的默认行为.

So I have a jQuery DateTimePicker v2.4.1 attached on a text input. I wanted to make it so then when the user clicks and changes the Month or Year of the picker - it would update the date within the form as this doesn't seem to be a default behavior of the plugin.

    $(timepicker).datetimepicker({
        format: "d M Y h:i A",
        step: 15,
        validateOnBlur: false, //use ValidateDateTime.js instead of jquery default
        closeOnInput: true,
        closeOnDateSelect: true,
        onClose: function() {
            var validatedDate = validateDate($(timepicker).val());
            if (validatedDate != false) {
                $(timepicker).val(validatedDate);
            }
        },
        changeMonth: true,
        changeYear: true,
        onChangeMonth: function() {
            //pop name of month into field and update calendar
            var d = $(this).datetimepicker('getDate');
            console.log(d + this.html());

            /*
            $(timepicker).datetimepicker.trigger("select.xdsoft", [d]);
            */
        }
    });

出现的问题是:var d = $(this).datetimepicker('getDate');实际上没有检索日期,而只是返回datetimepicker元素.

A problem that occurs is: var d = $(this).datetimepicker('getDate'); does not actually retrieve the date and just returns the datetimepicker element.

如何获取js中的日期或更具体的日期-当用户在下拉列表中单击一个月时,如何强制更新.

How do I get the date in js or more specifically - how could I force an update when the user clicks on a month within the drop down.

查看纪录片 http://xdsoft.net/jqplugins/datetimepicker/&多亏了Suish,它现在看起来像这样:

Looking at the documentary http://xdsoft.net/jqplugins/datetimepicker/ & thanks to suish it now looks like this:

onChangeMonth: function(date, $el) {
    //pop name of month into field and update calendar
    var str = dateTimeToString(date);
    $($el).datetimepicker({ value: str });
},

简单!

推荐答案

onChangeMonth函数(当前时间,$ input){}
onChangeYear函数(当前时间,$ input){}
onChangeDateTime函数(current_time,$ input){}

onChangeMonth function(current_time,$input){}
onChangeYear function(current_time,$input){}
onChangeDateTime function(current_time,$input){}

根据其文档.每个onChange函数都将Date变量作为第一个参数.

According to its documentation.each onChange functions get Date variable as a first parameter.

    onChangeMonth: function(date,$el) {
        var d = date.getDate();
        //d is selected date.
        var m = date.getMonth() + 1; //+1 because .getMonth() returns 0-11
        //m is selected month.
    }

这篇关于jQuery datetimepicker-如何在JavaScript中获取日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆