gpt4 book ai didi

jquery - $ ("#datePicker").datepicker ("getDate").getMonth 不是函数

转载 作者:行者123 更新时间:2023-12-01 00:37:25 24 4
gpt4 key购买 nike

尝试通过指向特定月份的链接来帮助实现此功能

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

我试过了

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

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

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

这里存在哪些问题?

请注意移动 jquery 和移动日期选择器添加的资源

最佳答案

该问题是由 jquery.ui.datepicker.mobile.js 引起的,无论您从何处获得该问题,这显然都是不完整的黑客攻击。

真正的问题在于这一行:

//return jqm obj 
return this;

这意味着无论你调用什么,它总是会为新的日期选择器返回被黑的 jQuery 对象。在您的情况下,它应该返回一个日期。

一个解决方案,这又只是一个 hack,是保存原始日期选择器调用的返回值,并且仅在原始返回值实际上是 jQuery 对象时才返回 jQuery 对象:

...

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

...

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

...

编辑:这一扩展的进一步问题是它破坏了所有需要多个参数的命令。 datepicker() 最多可以采用 5 个参数,因此这些额外参数必须传递到原始扩展。

同样,额外样式的添加和点击事件的绑定(bind)只能在构建日期选择器时进行,因此需要进行额外的检查以查看第一个参数的类型是否为是否为字符串。

生成的代码应该看起来像这样,我将剩下的留给原始开发人员:)。

(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 );

关于jquery - $ ("#datePicker").datepicker ("getDate").getMonth 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5926508/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com