How to format the datebox of easyui and the easyuidatebox
After reading a lot of solutions on the internet, I also wrote a simple method. Format the datebox of easyui. The effect is as follows, separated by "+ +" to see what you like.
1. html
<Span class = "span1"> valid certificate: </span> <input id = "passvali" name = "hotel. passvali"> </span>
2. js
/* The validity period of the credential is */$ ('# passvali '). datebox ({formatter: function (date) {var years = date. getFullYear (); // get the annual var months = date. getMonth () + 1; // obtain the daily var dates = date. getDate (); // obtain the month if (months <10) {// Add 0 before the month is less than 10, for example, 09 months = '0' + months ;} if (dates <10) {// Add 0 before the date is less than 10, for example, 09 dates = '0' + dates ;} return years + "++" + months + "++" + dates; // make changes as needed }});
Supplement:
The default format of DateBox date display is "dd/mm/yyyy". to customize the format, you need to implement two functions, formatter and parser.
The formatter function allows you to format a date as needed. After you select a date, the parser function tells the control how to parse the custom format.
Definition:
Formatter:A function to format the date, the function takes a 'date' parameter and return a string value.
Parser:A function to parse a date string, the function takes a 'date' string and return a date value.
For example, format the date to yyyy-mm-dd:
$('#dd1').datebox({ formatter: function(date){ return date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate();}, parser: function(date){ return new Date(Date.parse(date.replace(/-/g,"/")));}});
The above is the simplest method for formatting datebox of easyui, which is shared with you. I hope it will be helpful for your learning.