How to show date without year of jQuery UI datepicker

冷暖自知 提交于 2019-12-11 08:05:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!