[英]get id of calendar div on clicking next/prev button in calendar in jquery
I have showed multiple calendars on my page using jquery UI. 我已经使用jquery UI在页面上显示了多个日历。 The calendars are working fine. 日历工作正常。 I am trying to get the ID of the calendar when i click on next or previous button on the calendar. 当我单击日历上的下一个或上一个按钮时,我试图获取日历的ID。 The code i am using is this: 我正在使用的代码是这样的:
<div class="calendar" id="calendar1"></div>
<div class="calendar"id="calendar2"></div>
<div class="calendar" id="calendar3"></div>
and jquery code is 和jQuery代码是
$('.calendar').datepicker({
inline: true,
firstDay: 1,
showOtherMonths: true,
dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
});
$(document).on('click', '.ui-datepicker-next', function () {
console.log($(this).parent().parent().parent().attr('id'));
});
it should show calendar1/calendar2/calendar3 but instead on displaying id it shows undefined. 它应该显示calendar1 / calendar2 / calendar3,但在显示id时显示为undefined。 The datepicker html is this datepicker html是这个
<div class="calendar hasDatepicker" id="calendar1">
<div class="ui-datepicker-inline ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" style="display: block;">
<div class="ui-datepicker-header ui-widget-header ui-helper-clearfix ui-corner-all">
<a class="ui-datepicker-prev ui-corner-all" onclick="DP_jQuery_1488149175514.datepicker._adjustDate('#calendar50', -1, 'M');" title="Prev">
<span class="ui-icon ui-icon-circle-triangle-w">Prev</span>
</a>
<a class="ui-datepicker-next ui-corner-all" onclick="DP_jQuery_1488149175514.datepicker._adjustDate('#calendar50', +1, 'M');" title="Next">
<span class="ui-icon ui-icon-circle-triangle-e">Next</span>
</a>
as we can see the parent call is correct and it is working if i use 我们可以看到父级呼叫是正确的,如果我使用它可以正常工作
console.log($('.ui-datepicker-next').parent().parent().parent().attr('id'));
but that will always give the id of first div ie calendar1. 但这将始终给出第一个div的ID,即calendar1。
As of the Docs its: onChangeMonthYear( Integer year, Integer month, Object inst )
从文档开始: onChangeMonthYear( Integer year, Integer month, Object inst )
onChangeMonthYear:function(year, month, instance){
console.log(instance.id)
}
So try using: 因此,请尝试使用:
$('.calendar').datepicker({
inline: true,
firstDay: 1,
showOtherMonths: true,
dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
onChangeMonthYear:function(year, month, instance){
console.log(instance.id)
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.