问题
Normal behavior of datepicker is to open when a texbox is clicked and close when a date is selected(clicked). What I need to do is Keep it open from form load and allow user to click repeatedly.I am handling the click event
thanks
回答1:
According to the documentation, you can call it on a div instead of an input and it will stay open and be inline. http://jqueryui.com/demos/datepicker/#inline
You could use it's onSelect event to handle when a date is selected.
回答2:
If you are using the jQuery UI datepicker, use this:
http://jqueryui.com/demos/datepicker/#inline
You can then handle the click event and add the selected date to the text field.
回答3:
I totally agree with @Corbin I would like to provide full example so that help someone in details.
If you want to to have jQueryui calendar default open also capture the click event of calendar follow bellow steps:
HTML Code:
<div id="myDatePicker" class="DateBox datepicker" style="width:100%;height:200px;"></div>
<input type="hidden" id="dateHidden" name="dateHidden" />
and your script should look like bellow:
<script>
$( function() {
$( ".datepicker" ).datepicker({
altField: "#dateHidden",
dateFormat: 'yy-mm-dd'})
.datepicker("setDate", "0");
} );
</script>
and you can get the selected value of date like bellow code:
<script>
$("#dateHidden").on('input propertychange paste', function(){
var Loc = $("#Cafe").val();
var PDate = $("#dateHidden").val();
//------Functions you call or actions you perform--------//
//GetLoc(Loc,PDate);
});
</script>
来源:https://stackoverflow.com/questions/8531867/jquery-keeping-date-picker-open-all-the-time