Home >
Article > Web Front-end > jQuery ui uses the datepicker plug-in to implement the start date (minDate) and end date (maxDate)_jquery
jQuery ui uses the datepicker plug-in to implement the start date (minDate) and end date (maxDate)_jquery
WBOYOriginal
2016-05-16 16:47:141279browse
To use jQuery ui, you first need to introduce the jQuery class library, jQuery ui js script and jQuery ui css style sheet. The code example is as follows:
After implementing the above operation, click the text box on the page. If the datepicker appears, it means success.
Step 2 Set the start and end dates
When the start date value is selected, the minimum value of the end date should be the start date; similarly, when the end date is selected, the maximum value of the start date should be the end date. We can use the onSelect attribute in the datepicker to set the event that is triggered when the specified date is selected, and use this event to specify the corresponding datepicker minimum date or maximum date.
The Js code is as follows
Copy code
The code is as follows:$("#start").datepicker({ onSelect:function(dateText,inst){ $("#end").datepicker("option","minDate",dateText);
The second step: Also after selecting the date, trigger the onSelect event and call the function to pass the selectedDate parameter,
In the function body, first determine whether the trigger event is the start date or end date. Use this judgment to specify and set minDate or maxDate, and then use the not() function to reversely select another datepicker object and set its corresponding property.
The Js code is as follows
Copy code
The code is as follows:dates.datepicker({ onSelect: function( selectedDate){ var option = this.id == "start" ? "minDate" : "maxDate";
In this way, after setting one party, the other party will be restricted.
The effect achieved is as shown below:
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn