问题
I need to show date with day and month only, but if I set dateFormat: "d MM"
, I can not change year. It's always 2012. For example: http://jsfiddle.net/v2vcV/. Just try change date for January 2013 and reopen calendar, year will be still 2012.
回答1:
This can help you. HTML
<p>Date: <input type="text" style="visibility:hidden; width:0px" id="datepicker2"><input type="text" id="datepicker"></p>
JS
$(function() {
$("#datepicker").focus(function(){
$("#datepicker2").focus();
});
$("#datepicker2").datepicker({dateFormat: "dd MM yy",
onSelect:function(date){
$("#datepicker").val(date.substring(0,date.length-4));
}
});
});
Any way this is not the perfect way but can help what you want(as a illusion). if you want the exact date with year you can get it from datepicker2 textbox.
回答2:
I have made a small change but it gives you Year also, indeed it removes the bug you were facing
Check Here
using this resolves problem $( "#datepicker" ).datepicker({dateFormat: "dd MM yy"});
You can remove that year logically afterwards when the date is set.
I have made all edit changes and it works great now..Check Here
Enjoy.. :)
来源:https://stackoverflow.com/questions/13909577/how-to-show-date-without-year-of-jquery-ui-datepicker