如何在我的代码中动态创建calendar()的多个函数?
function calendar(){
new JsDatePick({
useMode:2,
target:'datepicker',
dateFormat:'%m-%d-%Y',
weekStartDay: 0
});
这是我的尝试,我很近,我几乎可以尝到它:
$(function() { $("[id^='datepicker']").each(function() { var id = parseInt(this.id.replace("datepicker", "")); function calendar+id(){ new JsDatePick({ useMode:2, target:'datepicker'+id, dateFormat:'%m-%d-%Y', weekStartDay: 0 }); } }); });
答案 0 :(得分:1)
是否需要多种功能。您可以将id
传递给日历功能,如下所示,
$(function() {
$("[id^='datepicker']").each(function() {
calendar(parseInt(this.id.replace("datepicker", "")));
});
function calendar(id){
new JsDatePick({
useMode:2,
target:'datepicker'+id,
dateFormat:'%m-%d-%Y',
weekStartDay: 0
});
}
});