2014-04-08 44 views
1

當我使我的datepicker只讀時,我看到用戶不能在文本框中輸入任何東西。但是,他們仍然可以使用日曆圖標更改值。如何隱藏日曆圖標以便用戶不能更改日期值?如何讓jQuery的日期選擇器按鈕圖像只讀

我不想禁用日期選擇器,因爲我需要在表單提交時將值發佈到服務器。

$(function() { 
    $(".datepicker").datepicker({ 
     showOn: "button", 
     buttonImage: "../calendar/images/calendar.gif", 
     buttonImageOnly: true, 
     changeMonth: true, 
     changeYear: true, 
     onClose: function() { 
      $(this).focus(); 
     } 
    }); 
});  
+0

問題中的標題聽起來有所不同,在您的問題中,您希望將整個日曆隱藏起來,並在標題中只希望圖像只能讀取?你想要什麼? –

+0

不,我想要文本框和img都應該只讀 – user3359065

+0

然後日曆圖標的目的是什麼? –

回答

2

沒有這樣做的東西,但你可以通過以下幾個方面:

您可以設置允許一些無效的範圍的範圍內,因此用戶不能選擇任何日期:

$(".datepicker").datepicker({ 
     minDate: -1, // Add this one further 
     maxDate: -2, // Add this one further 
     showOn: "button", 
     buttonImage: "../calendar/images/calendar.gif", 
     buttonImageOnly: true, 
     changeMonth: true, 
     changeYear: true, 
     onClose: function() { 
      $(this).focus(); 
     } 
}).attr('readonly', 'readonly'); 

JS Fiddle

1

就摧毀日期選擇器,當你輸入更改爲只讀:

$(".datepicker").datepicker("destroy").prop("readonly", true); 

Demo #1

或者,你可以隱藏圖像觸發:

$(".datepicker").prop("readonly", true).next("img").hide(); 

Demo #2

對於按鍵觸發,你可以簡單地禁用它:

$(".datepicker").prop("readonly", true).next("button").prop("disabled", true); 

Demo #3

相關問題