在jQuery Datepicker中将年份下拉列表替换为文本框
我试图用datepicker中的经典文本框替换年份下拉列表,因为我想手动输入年份。 我替换了它,但在datetime选择器中尝试单击day时,文本框中无法显示年份和整个日期。 我该怎么做 这是我的小提琴: 试试这个:在jQuery Datepicker中将年份下拉列表替换为文本框,jquery,drop-down-menu,textbox,jquery-ui-datepicker,Jquery,Drop Down Menu,Textbox,Jquery Ui Datepicker,我试图用datepicker中的经典文本框替换年份下拉列表,因为我想手动输入年份。 我替换了它,但在datetime选择器中尝试单击day时,文本框中无法显示年份和整个日期。 我该怎么做 这是我的小提琴: 试试这个: <div class="demo"> <p>Date: <input id="datepicker" type="text"></p> </div> $("#datepicker").on
<div class="demo">
<p>Date: <input id="datepicker" type="text"></p>
</div>
$("#datepicker").on("focus", function () {
bindCloseEvent();
});
$("#datepicker").datepicker({
changeMonth: true,
changeYear: true,
showButtonPanel: true,
onSelect: function() {
var curDate = $(this).datepicker('getDate');
var month = $(".ui-datepicker-month").val();
var year = $(".ui-datepicker-month").next("input").val();
$("#datepicker").datepicker('setDate', new Date(year, month, $.datepicker.formatDate('dd', curDate)));
},
}).bind("click", function () {
$(".ui-datepicker-month").change(function (e) {
bindCloseEvent();
});
});
function bindCloseEvent() {
var text = $("<input type='text'/>");
$(".ui-datepicker-year").before(text).hide();
$('.ui-datepicker-close').click(function (e) {
var curDate = $(this).datepicker('getDate');
var month = $(".ui-datepicker-month").val();
var year = $(".ui-datepicker-month").next("input").val();
$("#datepicker").datepicker('setDate', new Date(year, month, $.datepicker.formatDate('dd', curDate) + 1));
});
}
var d = $("#datepicker").datepicker('getDate') || new Date();
d.setFullYear(parseInt(this.value, 10));
$("#datepicker").datepicker('setDate', d);
日期:
$(“#日期选择器”)。关于(“焦点”,函数(){
bindCloseEvent();
});
$(“#日期选择器”)。日期选择器({
变化月:对,
变化年:是的,
showButtonPanel:是的,
onSelect:function(){
var curDate=$(this.datepicker('getDate');
var month=$(“.ui datepicker month”).val();
var year=$(.ui datepicker month”).next(“input”).val();
$(“#datepicker”).datepicker('setDate',新日期(年、月、$.datepicker.formatDate('dd',curDate));
},
}).bind(“单击”,函数(){
$(“.ui datepicker month”).change(函数(e){
bindCloseEvent();
});
});
函数bindCloseEvent(){
变量文本=$(“”);
$(.ui datepicker year”).before(text.hide();
$('.ui日期选择器关闭')。单击(函数(e){
var curDate=$(this.datepicker('getDate');
var month=$(“.ui datepicker month”).val();
var year=$(.ui datepicker month”).next(“input”).val();
$(“#datepicker”).datepicker('setDate',新日期(年、月、$.datepicker.formatDate('dd',curDate)+1));
});
}
var d=$(“#日期选择器”).datepicker('getDate')| new Date();
d、 setFullYear(parseInt(this.value,10));
$(“#datepicker”).datepicker('setDate',d);
小提琴:
<div class="demo">
<p>Date: <input id="datepicker" type="text"></p>
</div>
$("#datepicker").on("focus", function () {
bindCloseEvent();
});
$("#datepicker").datepicker({
changeMonth: true,
changeYear: true,
showButtonPanel: true,
onSelect: function() {
var curDate = $(this).datepicker('getDate');
var month = $(".ui-datepicker-month").val();
var year = $(".ui-datepicker-month").next("input").val();
$("#datepicker").datepicker('setDate', new Date(year, month, $.datepicker.formatDate('dd', curDate)));
},
}).bind("click", function () {
$(".ui-datepicker-month").change(function (e) {
bindCloseEvent();
});
});
function bindCloseEvent() {
var text = $("<input type='text'/>");
$(".ui-datepicker-year").before(text).hide();
$('.ui-datepicker-close').click(function (e) {
var curDate = $(this).datepicker('getDate');
var month = $(".ui-datepicker-month").val();
var year = $(".ui-datepicker-month").next("input").val();
$("#datepicker").datepicker('setDate', new Date(year, month, $.datepicker.formatDate('dd', curDate) + 1));
});
}
var d = $("#datepicker").datepicker('getDate') || new Date();
d.setFullYear(parseInt(this.value, 10));
$("#datepicker").datepicker('setDate', d);