Add custom parameter to jQuery UI Datepicker

后端 未结 1 1337
予麋鹿
予麋鹿 2021-01-14 20:26

I am looking for a way to add a parameter to the dates in the jQuery UI Datepicker. I am using the Datepicker to display course start dates. The parameter I need would be t

相关标签:
1条回答
  • 2021-01-14 21:03

    Heres my attempt using the onSelect method for datepicker.

    I have not updated the underlying Date object, instead just added a new data attribute to the "Result" input field. On select, it searches an object called courses (representing your list of course ids and dates) for a match for the selected date.

    Inspect the input field with firebug/developer tools to see the data-course-id attribute update. First 3 days of the month have associated courses...

    http://jsfiddle.net/Seandeburca/qbLwD/

    var input = $("#datepicker");
    var result = $("#result");
    
    var courses = {
        "01-09-2013" : "javascript",
        "02-09-2013" : "history",
        "03-09-2013" : "biology",
        "10-09-2013": "physics"
    };
    
    input.datepicker({
       dateFormat: 'dd-mm-yy',
       showWeek: true,
       firstDay: 1,
       numberOfMonths: 3, 
    
       onSelect: function(dateText, pickerObj){
    
         result.attr("data-course-id", courses[dateText]); 
         course.innerHTML = courses[dateText]; 
       },
    
       altField: "#result"
    });
    
    0 讨论(0)
提交回复
热议问题