2013-06-09 16 views
5

私はこのソースの日付ピッカーを使用しています。http://jqueryui.com/datepicker/#buttonbar、私はボタンバーの "今日"ボタンをアクティブにするようにしようとしています。日付選択ツールの今日のボタンをオンにする

$(".datepicker").datepicker({ 
    showOn: "button", 
    showButtonPanel: true, 
    buttonImage: buttonCalendar, 
    buttonImageOnly: true, 
    buttonText: "" 
}); 

を、これはあなたがカレンダーを持っているページ内のコードを呼び出すJS:

$(".datepicker").datepicker({ 
      showButtonPanel: true, closeText: 'Clear', 
      gotoCurrent : true, 
      changeMonth: true, 
      changeYear: true, 
      yearRange: '1900, 2300', 
      dateFormat: _DateFormatDatePicker,    
      onSelect: function (dateText, inst) { 
       dateAsString = dateText; //the first parameter of this function 
       var dateAsObject = $(this).datepicker('getDate'); //the getDate method 
       document.getElementById('<%=hdnTempDate.ClientID%>').value = dateText; 
      } 
+1

私 http://api.jqueryui.com/datepicker/#option-currentText – Alaa

+0

ワットは、あなたがそれを取得することにより、意味ですか」アクティブ "? –

+3

表示されているとおり単純ではありません。こちらをご覧ください:http://stackoverflow.com/questions/1073410/today-button-in-jquery-datepicker-doesnt-work –

答えて

12

これを試してみてください。

$.datepicker._gotoToday = function(id) { 
    $(id).datepicker('setDate', new Date()).datepicker('hide').blur(); 
}; 
+0

$ .datepicker._gotoToday = function(id){ $(id).datepicker( '新しい日付())。datepicker( 'hide')。blur(); }; ' –

+0

もう少し正確なのは' $(id).datepicker( 'setDate'、new Date())です。 – Kotodid

8

この

$(function() { 
    $("#datepicker").datepicker({ 
     showButtonPanel: true 
    }); 
}); 
2

がでボタン]パネルを有効にしてください:showButtonPanel: true。次に、あなたのDatePickerのJSコードの後に​​次のコードを配置:

あなたが答えるのを助けるかもしれ
var _gotoToday = jQuery.datepicker._gotoToday; 
jQuery.datepicker._gotoToday = function(a){ 
    var target = jQuery(a); 
    var inst = this._getInst(target[0]); 
    _gotoToday.call(this, a); 
    jQuery.datepicker._selectDate(a, jQuery.datepicker._formatDate(inst,inst.selectedDay, inst.selectedMonth, inst.selectedYear)); 
}; 
関連する問題