jQuery Datepicker localization

前端 未结 8 1302
我在风中等你
我在风中等你 2020-12-07 15:28

I need a french calendar and I can\'t understand the problem. I guess I\'m not using the regional options like it should be. But...

Here is my code :



        
8条回答
  •  无人及你
    2020-12-07 16:07

    You must extend the regional options like this (code split on multiple lines for readability):

    var options = $.extend(
        {},                                  // empty object
        $.datepicker.regional["fr"],         // fr regional
        { dateFormat: "d MM, y" /*, ... */ } // your custom options
    );
    $("#datepicker").datepicker(options);
    

    The order of parameters is important because of the way jQuery.extend works. Two incorrect examples:

    /*
     * This overwrites the global variable itself instead of creating a
     * customized copy of french regional settings
     */
    $.extend($.datepicker.regional["fr"], { dateFormat: "d MM, y"});
    
    /*
     * The desired dateFormat is overwritten by french regional 
     * settings' date format
     */
    $.extend({ dateFormat: "d MM, y"}, $.datepicker.regional["fr"]);
    

    PS: you also need to load the jQuery UI i18n files:

    
    

提交回复
热议问题