Допустим, что мы имеем:Javascript проблемы прослушивателя событий
//Some vars
function initialSetup(date){
// Call to some functions
}
function populateCalendar(date){
// Call to several function. Task : build and populate a calendar with the date
awesomeFunction() // Have to set click event listener
// If the function call purpose was detected as an update, return value
}
function awesomeFunction(){
// For each day in the calendar, if there is a click, set the displayed date as the correct month, then rebuild the calendar
$(".notInTheMonth").each(function(){
$(this).click(function(e){
//Some process
//Changing date
populateCalendar(processedDate)
updateCalendar(processedVar)
//Some another process
});
});
}
function updateCalendar(updated){
// Jquery transition from the old calendar to the new
// Will put the content of the updated var to replace the content in the table calendar
}
Когда календарь обновляется, событие не будет заменен, поэтому после того, как событие щелчка в календаре, он будет обновляться один раз, но не reput прослушиватель событий, предоставленный awesomeFunction
Так в чем же проблема?
Какая разница? –
@NicolasFrbezar: https://learn.jquery.com/events/event-delegation/ – Fidel90
Да, но в моем коде это та же история, нет? Когда есть щелчок, он заполнит новый календарь и установит свой слушатель событий для каждого элемента, а после анимации jquery новый элемент должен иметь новый прослушиватель событий. –