2013-12-10 46 views

回答

0

对于特定的jQuery UI日期选择器/实例,您可以使用dateFormat选项。

代码:

$("#datepicker2").datepicker({ dateFormat: 'yy' }); 

演示:http://jsfiddle.net/dyvH2/

+0

不同的配置设置。正如我上面提到的那样,如果可能的话,我需要将其设置为内联。我知道我可以做到这一点,实例化另一个字段ID或类,而不是默认值。但我正在寻找内联的东西。 – jfreak53

0

当初始化在许多元素插件,但需要根据元素实例特定的配置很容易通过each环内单独初始化他们这样做

/* loop over collection of elements*/ 
$('.datePickerClass').each(function(){ 

    var opts={/* your standard config, or leave as empty object if using all defaults*/ } 

    /* check some condition to isolate special cases*/ 
    if($(this).is('.datePickerSpecial')){ 
    /* modify config for this condition*/ 
    $.extend(opts, {dateFormat : "d M, y"}); 
    } 
    /* initialize current instance*/ 
    $(this).datepicker(opts); 

}) 

迈出这一步或者进一步你可以很容易地把它变成它自己的插件。您也可以使用data-属性来通过$.extend