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接受布尔值。

相关问题