$(“#datePicker").datepicker("getDate").getMonth不是函数 [英] $("#datePicker").datepicker("getDate").getMonth is not a function

查看:120
本文介绍了$(“#datePicker").datepicker("getDate").getMonth不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试通过指向特定月份的链接来帮助它工作

Trying to help getting this to work with a link to a specific month

http://jquerymobile.com/test/experiments/ui-datepicker/

我尝试过

http://jsfiddle.net/mplungjan/FQLjS/2/

  1. 默认日期不是六月初
  2. 我有一个可见的日历和另一个onclick.
  3. 我明白了

错误: $(#datePicker").datepicker("getDate").getMonth 不是函数
源文件: http://fiddle.jshell.net/mplungjan/FQLjS/2/show /
行:59

Error: $("#datePicker").datepicker("getDate").getMonth is not a function
Source File: http://fiddle.jshell.net/mplungjan/FQLjS/2/show/
Line: 59

这里有什么问题?

请注意从移动jquery和移动datepicker添加的资源

Please note the added resources from the mobile jquery and mobile datepicker

推荐答案

问题是由jquery.ui.datepicker.mobile.js引起的,无论您从哪里得到它,显然都是不完全的黑客行为.

The problem is caused by jquery.ui.datepicker.mobile.js, whereever you got that from, it's clearly an incomplete hack.

真正的问题是此行:

//return jqm obj 
return this;

这意味着无论您调用什么,它将始终为新的日期选择器返回被黑的jQuery对象.就您而言,它应该返回一个日期.

That means whatever you call, it will always return the hacked jQuery object for the new datepicker. In your case, it should return a date.

一种解决方案,它仍然只是黑客,它保存原始datepicker调用的返回值,并且仅在原始返回值实际上是jQuery对象的情况下才返回jQuery对象:

A solution, which is again just a hack, is to save the return value of the original datepicker call, and only return a jQuery object if the original return value was in fact a jQuery object:

...

//call cached datepicker plugin
var retValue = prevDp.call( this, options );

...

//return jqm obj
if(retValue){
    if(!retValue.jquery) return retValue;
}
return this;

...

扩展名的扩展问题在于,它会破坏所有需要多个参数的命令. datepicker()最多可以使用5个参数,因此这些附加信息必须传递给原始扩展名.

Further problems with this extension of an extension is that it breaks all commands which require more than one parameter. The datepicker() can take as many as 5 parameters, so these extras must be passed through to the original extension.

同样,仅在构造datepicker时,才应进行其他样式的添加和click事件的绑定,因此需要进行额外的检查以查看第一个参数的类型是否为是否为字符串.

Likewise, the adding of extra styles and the binding of the click event should only take place when the datepicker is being constructed, so there is an extra check that needs to be put in to see if the type of the first parameter is a string or not.

生成的代码应如下所示,其余部分留给原始开发人员:).

The resulting code should look something like this, I'll leave the rest up to the original developer :).

(function($, undefined ) {

    //cache previous datepicker ui method
    var prevDp = $.fn.datepicker;

    //rewrite datepicker
    $.fn.datepicker = function( options, param2, param3, param4, param5 ){

        var dp = this;

        //call cached datepicker plugin
        var retValue = prevDp.call( this, options, param2, param3, param4, param5 );

        //extend with some dom manipulation to update the markup for jQM
        //call immediately
        function updateDatepicker(){
            $( ".ui-datepicker-header", dp ).addClass("ui-body-c ui-corner-top").removeClass("ui-corner-all");
            $( ".ui-datepicker-prev, .ui-datepicker-next", dp ).attr("href", "#");
            $( ".ui-datepicker-prev", dp ).buttonMarkup({iconpos: "notext", icon: "arrow-l", shadow: true, corners: true});
            $( ".ui-datepicker-next", dp ).buttonMarkup({iconpos: "notext", icon: "arrow-r", shadow: true, corners: true});
            $( ".ui-datepicker-calendar th", dp ).addClass("ui-bar-c");
            $( ".ui-datepicker-calendar td", dp ).addClass("ui-body-c");
            $( ".ui-datepicker-calendar a", dp ).buttonMarkup({corners: false, shadow: false}); 
            $( ".ui-datepicker-calendar a.ui-state-active", dp ).addClass("ui-btn-active"); // selected date
            $( ".ui-datepicker-calendar a.ui-state-highlight", dp ).addClass("ui-btn-up-e"); // today"s date
            $( ".ui-datepicker-calendar .ui-btn", dp ).each(function(){
                var el = $(this);
                // remove extra button markup - necessary for date value to be interpreted correctly
                el.html( el.find( ".ui-btn-text" ).text() ); 
            });
        };

        if(typeof options != 'string'){
            //update now
            updateDatepicker();

            // and on click
            $( dp ).click( updateDatepicker );
        }

        //return jqm obj 
        if(retValue){
            if(!retValue.jquery) return retValue;
        }
        return this;
    };

    //bind to pagecreate to automatically enhance date inputs   
    $( ".ui-page" ).live( "pagecreate", function(){     
        $( "input[type='date'], input:jqmData(type='date')", this ).each(function(){
            $(this).after( $( "<div />" ).datepicker({ altField: "#" + $(this).attr( "id" ), showOtherMonths: true }) );
        }); 
    });
})( jQuery );

这篇关于$(“#datePicker").datepicker("getDate").getMonth不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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