Kod
function onload() {
cal1 = $("#kalendarz_gorny tr td[id^='day-']");
cal2 = $("#kalendarz_dolny tr td[id^='day-']");
cal1.each( function(i) {
$(this).click( function(event) {
event.preventDefault();
do_the_acting(this);
});
});
cal2.each( function(i) {
$(this).click( function() {
event.preventDefault();
do_the_acting(this);
});
});
}
cal1 = $("#kalendarz_gorny tr td[id^='day-']");
cal2 = $("#kalendarz_dolny tr td[id^='day-']");
cal1.each( function(i) {
$(this).click( function(event) {
event.preventDefault();
do_the_acting(this);
});
});
cal2.each( function(i) {
$(this).click( function() {
event.preventDefault();
do_the_acting(this);
});
});
}
Funkcja do_the_acting():
Kod
function do_the_acting(obj) {
//document.write(obj.id);
if( from == null ) {
from = obj.id.substr(4);
$(obj).addClass('selected');
}
else if( from == obj.id.substr(4) ) {
from = null;
$(obj).removeClass('selected');
days = new Array();
}
else
{
if( from < obj.id.substr(4) ) {
to = obj.id.substr(4);
$(obj).addClass('selected');
}
else {
to = from;
from = obj.id.substr(4);
$(obj).addClass('selected');
}
//document.write(obj.id);
if( from == null ) {
from = obj.id.substr(4);
$(obj).addClass('selected');
}
else if( from == obj.id.substr(4) ) {
from = null;
$(obj).removeClass('selected');
days = new Array();
}
else
{
if( from < obj.id.substr(4) ) {
to = obj.id.substr(4);
$(obj).addClass('selected');
}
else {
to = from;
from = obj.id.substr(4);
$(obj).addClass('selected');
}
Dlaczego funkcja przy każdym kliknięciu wywoływana jest 2 razy?
Widać to po dwukrotnym wypisaniu obj.id, jeśli je odkomentuję i po tym, że selected niemal od razu jest wyłączane.