Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/422.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 Calendar.setup获取所选日期_Javascript_Jquery_Html_Calendar - Fatal编程技术网

Javascript Calendar.setup获取所选日期

Javascript Calendar.setup获取所选日期,javascript,jquery,html,calendar,Javascript,Jquery,Html,Calendar,我正在编辑一个现有系统,他们正在使用Calendar.setup而不是jquery datepicker。我已经建议datepicker比calendar.setup更升级,但是他们仍然希望使用calendar.setup 我的问题是,我不知道如何获取所选日期的值 Calendar.setup ( { inputField : 'txtDate', // ID of the input field ifFor

我正在编辑一个现有系统,他们正在使用Calendar.setup而不是jquery datepicker。我已经建议datepicker比calendar.setup更升级,但是他们仍然希望使用calendar.setup

我的问题是,我不知道如何获取所选日期的值

 Calendar.setup
    (
        {
            inputField  : 'txtDate',       // ID of the input field
            ifFormat    : "%Y-%m-%d",       // The Date Format
            button      : 'txtDate'      // ID of the button
        }
    );
试试这个:

 Calendar.setup
    (
        {
            inputField  : 'txtDate',       // ID of the input field
            ifFormat    : "%Y-%m-%d",       // The Date Format
            button      : 'txtDate',      // ID of the button
            onSelect    : function(){
                              var calDate = this.selection.get();
                              var calHours = new String(this.getHours());
                              var calMinutes = new String(this.getMinutes());
                              var calTime = ((calHours.length == 1) ? '0'+calHours : calHours) + ((calMinutes.length == 1) ? '0'+calMinutes : calMinutes );
            }
        }
    );

你可能想对你的代码做一个简短的解释。嗨,我发现这篇文章很有帮助。但是有几个问题,正在获取的日期是这样的“20140520”,我如何将其格式化为“Y/m/d”?弄明白了,我们可以使用this.selection.print(格式,分隔符)。参考文档:请使用更多信息进行编辑。不鼓励只编写代码和“尝试此”答案,因为它们不包含可搜索的内容,并且不解释为什么有人应该“尝试此”。欢迎使用堆栈溢出!虽然这个代码片段可以解决这个问题,但它确实有助于提高文章的质量。请记住,您将在将来回答读者的问题,这些人可能不知道您的代码建议的原因。还请尽量不要用解释性注释挤满您的代码,因为这会降低代码和解释的可读性!
var cal=Calendar.setup
    (
        {
            inputField  : 'txtDate',       // ID of the input field
            ifFormat    : "%Y-%m-%d",       // The Date Format
            button      : 'txtDate',      // ID of the button

        })
var seldate=cal.date