0

我使用jQuery UI的日期選擇器,但我想顯示週數只有當輸入元素具有一個特定的類...jQuery的日期選擇器 - 顯示週數,如果有特定的類

這裏是我已經試過但沒有成功...

$(".myCal").datepicker({ 
    showWeek: function(dateText, inst) { $(this).hasClass("showWeek"); } 
}); 
+1

是否缺少您的匿名功能的 「迴歸」? – strauberry 2013-04-11 14:25:20

回答

1

由於使用了類選擇器,所以需要使用每個方法遍歷所有匹配的元素,然後使用$(this)。

$(".myCal").each(function() { 
    $(this).datepicker({ 
     showWeek: $(this).hasClass('showWeek') 
    }); 
}); 

http://jsfiddle.net/Ubw3L/5/

0
$('.myCal').each(function() { 
    $(this).datepicker({ 
    showWeek: $(this).hasClass('showWeek'); 
    }); 
}); 
+0

您編輯的答案是[我的答案](http://stackoverflow.com/a/15951644/504368)的副本。沒問題,只是爲了公平競爭:) – 2013-04-11 15:25:22

+0

只是upvoted你的答案;) – AnthonyLeGovic 2013-04-11 15:28:30

+0

公平不夠!謝謝 ;) – 2013-04-11 15:29:45

0

你能試試這個

$(".myCal").datepicker({ 
    showWeek: $(this).hasClass("showWeek"); 
}); 

隨着API狀態, showWeek接受布爾值。

相關問題