If you encounter the same problem when the time is tight and the task is heavyProgramMember brother, please read it directlyCode.
Recently it almost became a javascript front-end programmer... Originally, I wanted to focus only on the background ...... No way. Work is required ~
Today, a colleague suddenly ran over and asked me if the datepicker in jquery UI could add a clear button to clear it with one click. I think the powerful datepicker must have taken this requirement into consideration, maybe it was a simple property setting thing. As a result, I was disappointed. datepicker didn't provide the clear function. Google had a chat and concluded that it may have been, but it was removed for some reason from a certain time and never came back again. Some people on the internet gave some severe hack practices and added a clear button to the HTML function generated by the control. This is not an act for JavaScript cainiao of my generation, even if it is just copy & paste. in fact, datepicker provides two buttons, today and done. Why don't we start with this done button to make it clear and transform it into a clear button, at the same time, try to patch only the peripheral components of the control? After analyzing the HTML generated by datepicker, it seems that it is not difficult. You only need to use the following code to solve the problem.
1 $ (Document). Ready ( Function ()
2 {
3 // It is used to store references to the date text box currently being operated.
4 VaR Datepicker_currentinput;
5
6 // Set Default datepicker settings
7 $. Datepicker. setdefaults ({showbuttonpanel: True , Closetext: 'clear', beforeshow: Function (Input, insT) {datepicker_currentinput = input ;}});
8
9 // Bind the Click Event of the "done" button. When triggered, clear the value of the text box.
10 $ (". UI-datepicker-Close"). Live ("click ", Function ()
11 {
12 Datepicker_currentinput.value = "";
13 });
14 });