2012-10-16 36 views
1

有大量的問題和答案,但我找不到我在找什麼。無法隱藏jQuery UI的日期選擇器

我顯示的日期選擇器鏈接點擊,但不能隱藏它時,用戶選擇一個日期。如果您有任何建議,請讓我知道。您可以在http://jsfiddle.net/5qE8K/

$("#calendar > a").unbind('click').bind('click', function(e){ 
     e.preventDefault(); 

     var calendar = $(this).parent(); 

     $("#content").datepicker({ 
      beforeShow: function(){ 
       $(".ui-datepicker").css({ 
        'position' : 'absolute', 
        'top'  : (calendar.offset().top + calendar.height() + 4) + 'px', 
        'left'  : (calendar.offset().left + calendar.width() - $(".ui-datepicker").outerWidth(true)) + 'px' 
       }); 
      }, 
      onSelect: function(date, obj){ 
       calendar.children("div#selected-date").text(obj.selectedDay + '/' + (obj.selectedMonth+1) + '/' + obj.selectedYear); 
       calendar.children("span").text(obj.selectedDay); 
       $("#content").datepicker('hide'); 
      } 
     }); 
    }); 
+1

請提供一個jsfiddle測試用例.. – Nelson

+0

嘿尼爾森,我添加了jsfiddle鏈接。謝謝。 – Tim

回答

0

找到相關的代碼中調用「隱藏」在一個內聯detepicker(即連接到除輸入以外的其他元素的日期選擇器),什麼都不做。嘗試調用銷燬。

// ... 
calendar.children("span").text(obj.selectedDay); 
$("#content").datepicker('destroy'); 
// ... 
+0

我也試過這個,但奇怪的是,這個刪除了$(「#content」)。 – Tim