The easyui date control datebox is used to display only the year and month, and only the year and month can be selected (active in the test, invalid video hanging)

Source: Internet
Author: User

VaR node = $ ('input [name = "createtime"] ');
Node. datebox ({
Onshowpanel: function () {// display the date selection object and then trigger the event at the month layer. The month layer is not generated during initialization.
Span. Trigger ('click'); // trigger the click event to bring up the month layer.
SetTimeout (function () {// delay trigger to obtain the month object, because the previous event trigger and object generation have time intervals.
VaR tabletd = P. Find ('div. Calendar-menu-month-inner TD ');
Tabletd. On ("click", function (e ){
E. stoppropagation (); // disable bubbling to execute the event that easyui binds to the month.
VaR event = e.tar get, // the current month to be clicked
Y =/\ D {4}/.exec(span.html () [0], // year
M = parseint ($ (Event). ATTR ("abbr"); // month
If (M <10) M = "0" + m;
Node. datebox ('hidemopanel '); // hide a date object
Node. datebox ('setvalue', Y + '-' + M); // you can specify the date value.
});
}, 0 );
},
Formatter: function (date) {// format the date
Var y = date. getfullyear (),
M = date. getmonth () + 1;
If (M <10) M = "0" + m;
Return y + "-" + m;
},
Parser: function (s) {// parses a date string
VaR T = date. parse (s );
Return! Isnan (t )? New Date (t): new date ();
}
});
VaR P = node. datebox ('panel '); // Date selection object
VaR span = P. Find ('div. Calendar-title span '); // display the trigger control of the month layer.

1. The basic practice is to trigger a click on the month column of the window title after the pop-up date window. The pop-up is the month window.
Return to the date window of the month after selecting the month in the easyui default month window, cancel the operation, and display the month in the input box.
2. The variable P is the original date selection box.

3. The variable span is the year and month shown on the top of the date selection box. The code on the Internet is to get this element wrong.

 

4. After the click year/month operation is triggered, the HTML code of the month pop-up window is generated temporarily. Therefore, setTimeout is required to obtain the subsequent content in a delayed manner.

 

5. The variable "TDS" is used to click the "month" button in the "month" selection box displayed after the year and month. In fact, Div. calendar-menu-month-inner contains a table, and those month buttons are the TD cells in the table.

6. E. stoppropagation () is used to prevent passing the time after the month is clicked to the upper-level Dom, but it is not necessary.

7. TD has the abbr attribute, which records the actual number of months of the month button, ranging from 1 to 12. 0 is not filled by default. In the code, I add 0.

 
Note: The test is effective. Hope to help you!

 

The easyui date control datebox is used to display only the year and month, and only the year and month can be selected (active in the test, invalid video hanging)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.