簡體   English   中英

jQuery 日期選擇器未在外部單擊時關閉

[英]jQuery date picker not closing on outside click

我有一個 jquery 日期選擇器,在單擊圖標時會打開。 日期選擇器正確打開,邏輯也正確發生。 我面臨一個問題,即單擊外部(或失去焦點)時日期選擇器沒有關閉。 單擊外部時如何關閉日期選擇器?

代碼是這樣的

<i class="fad fa-calendar-week" id="edit-checkin-date" onclick="editCheckoutDates();"></i>

function

function editCheckoutDates(){
  jQuery(function ($) {
  jQuery("#edit-checkin-date")
  .datepicker({
    language: "en",
    range: true,
    dateFormat: "M d",
    multipleDatesSeparator: " - ",
    minDate: from_min_date,
    maxDate: to_max_date,
    onSelect: function(formattedDate, date, inst) {
      if (date[0]) {  
        $("#from").val(
          ("0" + (date[0].getMonth() + 1)).slice(-2) +
          "/" + //month
          ("0" + date[0].getDate()).slice(-2) +
          "/" + //day
            date[0].getFullYear()
        ); //year);
      }
      if (date[1]) {
        $("#to").val(
          ("0" + (date[1].getMonth() + 1)).slice(-2) +
          "/" + //month
          ("0" + date[1].getDate()).slice(-2) +
          "/" + //day
            date[1].getFullYear()
        ); //year);
      }

      if (2 !== date.length) return;

    }
  });
});
}

單擊上述圖標時,日期選擇器在此處打開。 但問題是在日期選擇器之外單擊時不會關閉。

嘗試添加這個,

$("#edit-checkin-date").on("blur", function(e) { $(this).datepicker("hide"); });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM