jQuery datepicker-动态altfield问题 [英] jquery datepicker - dynamic altfield issue
本文介绍了jQuery datepicker-动态altfield问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在一个页面上有多个日期选择器...除altfield部分外,其他所有功能似乎都工作正常...
I have multiple datepickers on a page... all seems to be working fine except I the altfield part...
这可能吗?
$(document).ready(function(){
$( ".datepicker" ).datepicker({
beforeShowDay: function(date){ return [(date.getDay() == 1 || date.getDay() == 4), ""] },
showOn: "button",
buttonText: "Book now...",
showWeek: true,
firstDay: 1,
onSelect: function(date) {
$(this).parent().find('.selecteddate').prepend("Date: " + $(this).parent().find('.datepicker').val() + " - <a href='javascript:;' class='cleardate'>clear date</a>");
$(this).parent().find('button').hide();
},
dateFormat: "DD, d MM, yy",
altField: $(this).closest('div').find('.datepickeralt'),
altFormat: "dd/mm/yy",
navigationAsDateFormat: true,
minDate: 0,
});
$(".cleardate").live('click',function(){
$(this).closest('div').find('.datepicker').datepicker("setDate", null);
$(this).closest('div').find('.datepickeralt').val("");
$(this).closest('div').find('button').show();
$(this).parent().html("");
});
});
推荐答案
Yes you can do exactly that, you just need to instantiate the date pickers with a .each()
loop, like this:
$('.datepicker').each(function() {
$(this).datepicker({
altField: $(this).closest('div').find('.datepickeralt')
});
});
在 .each()
this
内,这种方式表示您想要的每个日期选择器,然后找到其替代字段. 您可以在这里尝试一下.
This way inside the .each()
this
refers to what you want, each individual date picker, then finding its alt field. You can give it a try here.
这篇关于jQuery datepicker-动态altfield问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文