【问题标题】:jQuery datepicker not closingjQuery datepicker 没有关闭
【发布时间】:2011-04-06 09:40:57
【问题描述】:

我的 jQuery 日期选择器仅在选择日期时关闭,但我希望它在用户单击关闭按钮或关闭按钮时关闭。但是,即使将 showButtonPanel 选项设置为 true,关闭按钮也不会出现,但“今天”按钮会出现。

我认为它可能与使用自定义 onSelect 操作而不是默认操作有关,但无法弄清楚如何自己关闭它。尝试使用 $.datepicker('hide') 和 ('destroy') 但没有区别。

$(document).ready(function() {
    $.datepicker.setDefaults({firstDay: 1, dateFormat: 'dd/mm/yy', showAnim: 'fade'});
});    
$(document).delegate('.editEndDate', 'click', function() {              
$('.formattedEndDate').datepicker({
    defaultDate: $('.formattedEndDate').attr('id'),
    onSelect: function(dateText, inst) { 
    var date = dateText;
    var data = 'project=' + projectId + '&date=' + date + '&dateToChange=end';
        $.ajax({
            type: 'POST',
            url: 'helpers/change-project-date.php',
            data: data + '&ajax=1',
            success: function(response){
                getNotification(response);
                $('.formattedEndDate').fadeOut(function() {
                    $(this).load(location.href+ ' .formattedEndDate', function() {
                        $(this).fadeIn('slow');
                    });
                });     
            },
            error: function(response){
                getNotification(response);
            },
            complete: function(response){
                $('.formattedEndDate').datepicker('hide');
            }
        });
    }
});
return false;
});

这可能很简单,但我就是看不到。提前致谢。

【问题讨论】:

  • 使用这个脚本 $(document).click(function (e) { var ele = $(e.target); if (!ele.hasClass("hasDatepicker") && !ele.hasClass( "ui-datepicker") && !ele.hasClass("ui-icon") && !$(ele).parent().parents(".ui-datepicker").length) $(".hasDatepicker").datepicker ("隐藏"); });

标签: jquery-ui datepicker


【解决方案1】:

我可能已经找到了解决我自己问题的方法...

$('.ui-datepicker').live('mouseleave', function() {
    $('.ui-datepicker').fadeOut(function() {
        $('.formattedStartDate').attr('class', 'formattedStartDate');
        $(this).remove();
    });
});

这对我有用,希望对其他人也有用。

【讨论】:

    【解决方案2】:

    当我尝试使用 live 时,一切都崩溃了。所以我不得不使用on。我还添加了输入焦点隐藏。因此,如果您碰巧专注于不同的领域,日历就不会只是闲逛。我也只是隐藏了,但如果这是你想要的,你应该可以将它切换为淡入淡出。

        $('.bootstrap-datetimepicker-widget').on('mouseleave', function () {
            $(this).hide();
        })
        $('input').on('focus', function () {
            $('.bootstrap-datetimepicker-widget').hide();
        });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-26
      • 2014-07-25
      • 2023-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多