最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Hide the datepicker on blur event - Stack Overflow

programmeradmin1浏览0评论

I am trying to add an event blur on input in order to hide a calendar.
The plugin I am using to show the calendar is the foliowing eternicode/bootstrap-datepicker.

Here is the source code /

var inputs = $('.datepicker').datepicker({
    autoclose: true
});

inputs.on('blur', function () {
          console.log($(this));
          // I would like to hide just the date picker
          //$(this).hide();
});

I am trying to add an event blur on input in order to hide a calendar.
The plugin I am using to show the calendar is the foliowing eternicode/bootstrap-datepicker.

Here is the source code http://jsfiddle.net/KLpq7/75/

var inputs = $('.datepicker').datepicker({
    autoclose: true
});

inputs.on('blur', function () {
          console.log($(this));
          // I would like to hide just the date picker
          //$(this).hide();
});
Share Improve this question edited Oct 2, 2012 at 14:19 Lorraine Bernard asked Oct 2, 2012 at 13:15 Lorraine BernardLorraine Bernard 13.4k23 gold badges85 silver badges137 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 9

You can try this:

var inputs = $('.datepicker').datepicker({
format: 'yyyy-mm-dd',
autoclose: true}).on('changeDate', function (ev) {
         $(this).blur();
         $(this).datepicker('hide');
     });

Fiddle: http://jsfiddle.net/KLpq7/82/

    inputs.on('blur', function () {
        inputs.datepicker('hide');
    });

This is a known bug* -- if you use "datepicker" as the class for your inputs, it will interfere with the datepicker code, because datepicker is also the class used for the picker pane. Using a different class for your pickers should fix the issue for now.

* There aren't any open tickets for it at the moment, but it is acknowledged as a minor bug

Try this updated fiddle. I think that since you were using a class selector there was some conflicts in the blur event handler. I have separated each calendar picker by ID and it seems to work fine now.

发布评论

评论列表(0)

  1. 暂无评论