所以我只希望在我的日历用户界面上有一个选定的日期,但是当我按下新的日期时,旧日期仍然亮起,所以我可以按下我日历上的所有日期并且他们会一切都亮了。
for(var dayCounter = 1; dayCounter <= currMonthDays; dayCounter++){
tempListItem = document.createElement("li");
tempListItem.innerHTML = dayCounter;
$(tempListItem).addClass("day");
//add a hidden element to the day that we can access when we click on it
var temp = months[currMonth] +"/" + dayCounter +"/" + currFullYear;
$(tempListItem).append("<div class = 'hidden'>" + temp + "</div>");
if(dayCounter == date.getDate() && currMonth == date.getMonth()){
tempListItem.setAttribute("id", "current-day");
}
ulDays.appendChild(tempListItem);
}
$(document).on("click", ".day", function()
{
var date = $(this).children(".hidden").text();
console.log(date);
$(document.getElementById("current-day")).removeAttr("#current-day");
$(this).attr("id", "current-day");
});
删除当前课程后,该元素是否应该丢失其CSS?
答案 0 :(得分:0)
当您尝试从id
移除current-day
时,看起来您有一个小的。 removeAttr
期望属性的名称。在这种情况下,该属性将为id
,因此请尝试以下操作:
$(document.getElementById("current-day")).removeAttr("id");