日期选取器 onSelect 函数不从自身检索之前添加的类



这是我的代码

 onSelect: function (dateText, inst)
 {
    inst.inline = false;
    $(".ui-datepicker-current-day").addClass("markupDate");
 }     

当我检查 HTML 代码时,类"标记日期"已成功添加到 HTML 元素中。

我选择另一个日期,然后用我的onSelect函数检查日期是否已经有一个"markupDate"类。

问题是,当我点击一个已经具有类"标记日期"的日期时,我用jQuery询问单元格是否有类"markupDate",结果是假的。

但是当在 chrome 中检查元素时,$(".ui-datepicker-current-day") 已经类了"markupDate"!

这是代码

    onSelect: function (dateText, inst)
 {
     //no markupDate class in the result !
    console.log(($(".ui-datepicker-current-day").attr("class")));
    inst.inline = false;
     /*result is ever false !*/
    if($(".ui-datepicker-current-day").hasClass("markupDate")){
    //do something
    }else{
    $(".ui-datepicker-current-day").addClass("markupDate");
  }
 }  

jquery-ui 库中的_selectDay代码是

    _selectDay: function (a, b, c, d) {
        var e = $(a);
        if ($(d).hasClass(this._unselectableClass) 
  ||  this._isDisabledDatepicker(e[0])) 
   return;
   /*i put my code here and i return  =>my code is working */
     var f = this._getInst(e[0]);
      f.selectedDay = f.currentDay = $("a",d).html(), f.selectedMonth = 
     f.currentMonth = b, f.selectedYear =f.currentYear = c, 
    this._selectDate(a, this._formatDate(f, f.currentDay, f.currentMonth, 
    f.currentYear))

当我直接在里面添加我的代码时,我在此行之前返回:

          var f = this._getInst(e[0]);

onSelect 函数检索 $(".ui-datepicker-current-day") 是否具有类"markupDate"。

感谢您的任何帮助。

一看,您使用的是haveClass而不是hasClass。

更改此内容

 if($(".ui-datepicker-current-day").haveClass("markupDate")){

 if($(".ui-datepicker-current-day").hasClass("markupDate")){

最新更新