Javascript datePicker onSelect函数不从其自身检索之前添加的类
这是我的密码Javascript datePicker onSelect函数不从其自身检索之前添加的类,javascript,jquery,jquery-ui,datepicker,jquery-multidatespicker,Javascript,Jquery,Jquery Ui,Datepicker,Jquery Multidatespicker,这是我的密码 onSelect: function (dateText, inst) { inst.inline = false; $(".ui-datepicker-current-day").addClass("markupDate"); } 当我检查html代码时,类“markupDate”被成功地添加到html元素中 我选择另一个日期,然后用onSelect函数检查该日期是否已经有“markupDate”类。如果没有,我添加它 问题是这样的,当我点击一个
onSelect: function (dateText, inst)
{
inst.inline = false;
$(".ui-datepicker-current-day").addClass("markupDate");
}
当我检查html代码时,类“markupDate”被成功地添加到html元素中
我选择另一个日期,然后用onSelect函数检查该日期是否已经有“markupDate”类。如果没有,我添加它
问题是这样的,当我点击一个已经有类“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")){
到
是的,我会编辑我的帖子,谢谢。在prod中,我使用的是hasClass,这不是问题所在。而且,你不必检查。当addClass已经拥有该类时调用它不会添加两次。
if($(".ui-datepicker-current-day").hasClass("markupDate")){