开发者

jQuery - Calendar plugin, pre selected dates on multiple select

开发者 https://www.devze.com 2023-02-04 06:36 出处:网络
Im using a calendar plugin for jQuery, im using the \'selecting multiple dates\' demo which is here http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerMultiple.html

Im using a calendar plugin for jQuery, im using the 'selecting multiple dates' demo which is here http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerMultiple.html

Im using the demo code for starters which is as follows:

<script type="text/javascript" charset="utf-8">
$(function()
{
    $('.date-pick')
        .datePicker(
            {
                createButton:false,
                displayClose:true,
                closeOnSelect:false,
                selectMultiple:true
            }
        )
        .bind(
            'click',
            function()
            {
                $(this).dpDisplay();
                this.blur();
                return false;
            }
        )
        .bind(
            'dateSelected',
            function(e, selectedDate, $td, state)
            {
                console.log('You ' + (state ? '' : 'un') // wrap
                    + 'selected ' + selectedDate);

            }
        )
        .bind(
            'dpClosed',
            function(e, selec开发者_运维技巧tedDates)
            {
                console.log('You closed the date picker and the ' // wrap
                    + 'currently selected dates are:');
                console.log(selectedDates);
            }
        );
});
</script>

This works great, i want to be able to pre select dates somehow, im getting dates from the database, and i want to be able to show them as checked when i click the link to open the calendar.

If anyone has any experience with this, i would love some help ... im not a jQuery nut at all, so its hard to figure this out.

Cheers,


You can call the dpSetSelected method to set the dates you need, one at a time

Whatever code you use to get the list of dates from the database, run loop over them

var arrDates = ['01/01/2010', '01/05/2010', '01/10/2010'];
var dp = $('.date-picker');
for(var i = 0; i < arrDates.length; i++){
    dp.dpSetSelected(arrDates[i]);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消