How do i dymanically set range of date into jquery datepicker?
I have gotten the earliest date and latest date via
$query = "SELE开发者_如何学编程CT MIN(date_added) FROM books
UNION SELECT MIN(date_created) FROM news
UNION SELECT MIN(date_created) FROM registered_member
UNION SELECT MIN(date_of_rental) FROM rent
UNION SELECT MIN(datetime) FROM shopping_cart";
this returns me the earliest and latest.
I was thinking how do i use the data return to put into the range of jquery datepicker? This is my current code without any options added.
<script type="text/javascript">
$(document).ready(function() {
$( "#datepicker" ).datepicker(); });
</script>
If I understand you properly you might use minDate
and maxDate
options like:
$( "#datepicker" ).datepicker("option", "minDate", YourMinDate);
$( "#datepicker" ).datepicker("option", "maxDate", YourMaxDate);
Also you may use it in constructor:
$( "#datepicker" ).datepicker({
minDate: YourMinDate,
maxDate: YourMaxDate
});
<script type="text/javascript">
$(document).ready(function() {
$('.datepicker').datePicker({
startDate: '<?php echo $mindate; ?>', // MM/DD/YYYY format
endDate: '<?php echo $maxdate; ?>' // MM/DD/YYYY
});
});
</script>
When you initialize the plugin you can just supply the min and max as options
var myMinDate = ...;
var myMaxDate = ...;
$("#datepicker").datepicker({minDate: myMinDate, maxDate: myMaxDate});
See the datepicker documentation here for more info
精彩评论