Datepicker show legenda下个月会在点击下个月消失

时间:2013-02-24 09:59:57

标签: jquery datepicker jquery-ui-datepicker

我的日期选择器下面有一个漂亮的传奇,它工作正常,直到你下个月点击。我添加了链接因为很难解释,点击“Prijzen 2013”​​标签,然后点击periode toevoegen添加日期选择器。

https://www.huurhulp.nl/wijzigen/wijzigen.php?wijzigen_adv=4&code=321fa6715e552e9bd495753f44b04db8

这是完成工作的功能(在datepicker中显示之前):

function insertMessage() {
    var legenda = '<div class="legenda"><table cellpadding="0" cellspacing="0" style="font-size:11px;color:silver;"><tr><td>Let op! Overlap in afwijkende prijzen is niet mogelijk.</td><td>Gesloten:&nbsp;&nbsp;</td><td style="background-color:red;width:15px;"></td>'
    legenda = legenda + '<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Afwijkende prijs:</td><td style="background-color:#00A800;width:15px;"></td></tr></table></div>';
    clearTimeout(insertMessage.timer);
    if ($('#ui-datepicker-div .ui-datepicker-calendar').is(':visible')){
        $('#ui-datepicker-div').append(legenda);
    }
    else {
       insertMessage.timer = setTimeout(insertMessage, 10);
    }
}

我尝试了这个,但不起作用:

$('#ui-datepicker-div').delegate('.ui-datepicker-prev, .ui-datepicker-next', 'click', insertMessage);

2 个答案:

答案 0 :(得分:2)

function insertMessage(next) {
var legenda = '<div class="legenda"><table cellpadding="0" cellspacing="0" style="font-size:11px;color:silver;"><tr><td>Let op! Overlap in afwijkende prijzen is niet mogelijk.</td><td>Gesloten:&nbsp;&nbsp;</td><td style="background-color:red;width:15px;"></td>';
legenda = legenda + '<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Afwijkende prijs:</td><td style="background-color:#00A800;width:15px;"></td></tr></table></div>';
clearTimeout(insertMessage.timer);
if ($('#ui-datepicker-div .ui-datepicker-calendar').is(':visible')){
    if (next == 1){
        insertMessage.timer = setTimeout(insertMessage, 10);
    }        
    $('#ui-datepicker-div').append(legenda);
}
else {
   insertMessage.timer = setTimeout(insertMessage, 10);
}

}

答案 1 :(得分:1)

根据文档hereonChangeMonthYear函数可能就是您所需要的。

$('#ui-datepicker-div').datepicker({
  ...
  onChangeMonthYear: function( year, month, inst ) {
    insertMessage();
    },
  }
});

或类似的东西。当datepicker移动到新的月/年时调用它。