私はこのコードが列のすべての見出しで機能しない理由を調べています。このコードはどの列でも最初に機能しますが、クリックイベントは2回目に発生しません。ヘッダーのth
にはなぜ$(ColTh).click(function()
が添付されていませんか?すべての列見出しのクリックイベントをバインドできません。一度だけ動作します
$("table.ui-datepicker-calendar > thead").find("th[scope='col']").each(function() {
var ColTh = $(this);
$(ColTh).click(function() {
var colIndex = $(ColTh).index();
var dateList = [];
$(ColTh).closest('table').find('tr').each(function() {
var dateTd = $(this).find('td:eq(' + colIndex + ')');
var month = $(dateTd).attr('data-month'); //.trigger('click');
var year = $(dateTd).attr('data-year');
var day = $(dateTd).children(0).text();
if (typeof month != 'undefined') {
var monthINT = parseInt(month.trim());
monthINT = monthINT + 1;
var newDate = monthINT + '-' + day.trim() + '-' + year.trim();
dateList.push(newDate);
}
});
$('#itemSchedulerCal').multiDatesPicker('addDates', dateList);
dateList = [];
});
});
私はDatePickerの機能が再びすべての要素を再描画し、もはやイベントをバインドされていない新しい要素があるので、以来からだと思います。関数の委譲を使用する必要があり、それぞれをループする必要はありません。 – DaniP
委任を使用するだけではどうですか? $ {ColTh} .index($ {ColTh}); $ {ColTh = this、colIndex = $(ColTh).indexは、 (); ....}) ' –
私はここで委任をどのように使うことができますか? – youngseagul