0

フル カレンダーを使用していますが、翌月/年をクリックすると、すべてのテーブルの td フィールドが更新されます。

すべてのデータが更新されonClickたら、新しいデータも取得する必要があります。

リフレッシュするためのコードは以下のとおりです

 function updateCells(firstTime) {
//alert('called');
var startYear = t.start.getFullYear();
var today = clearTime(new Date());
var cell;
var date;
var row;
subTables.each(function(i, _sub){
var d = cloneDate(t.start);
d.setFullYear(d.getFullYear(),i,1);
d.setFullYear(d.getFullYear(),i,1-d.getDay());
$(_sub).find('td').each(function(ii, _cell) {

    cell = $(_cell);
    if (d.getMonth() == i) {
        cell.removeClass('fc-other-month');
    }else{
        cell.addClass('fc-other-month');
    }
    if (+d == +today && d.getMonth() == i) {
        cell.addClass(tm + '-state-highlight fc-today');
    }else{
        cell.removeClass(tm + '-state-highlight fc-today');
    }
    cell.find('div.fc-day-number').text(d.getDate());
    cell.find('div.fc-day-number').setAttribute('onClick','clicked("' + d.getDate() + '"');
    //document.getElementsByTagName('div.fc-day-number').setAttribute('onClick','clicked("' + d.getDate() + '"');
    addDays(d, 1);
});
});
bodyRows.filter('.fc-year-have-event').removeClass('fc-year-have-event');
 }

エラーは

TypeError: document.getElementsByTagName(...).setAttribute is not a function

onClick イベントで新しいデータを設定する方法を知っている人はいますか。

4

2 に答える 2

2

この関数は、ノードのコレクションであるNodeListgetElementsByTagName()を返すため、それを繰り返し処理し、それぞれを個別に処理する必要があります。

var nodes = document.getElementsByTagName(...);
for(var i = 0; i < nodes.length; i++) {
    var node = nodes[i];
    node.setAttribute(...);
}

関数が完全なセレクターで動作するように設計または意図されているとは思いませんが、タグ名のみです (そう'div'ではなく'div.fc-day-number')。

代わりに、次のようにすることもできます。

cell.find('div.fc-day-number').off('click').click(function(e) {
   clicked(d.getDate());
});
于 2013-01-21T12:41:51.183 に答える
1
var i = 0;
$(_sub).find('td').each(function(ii, _cell) {
    document.getElementsByTagName('div.fc-day-number')[i].setAttribute('onClick','clicked("' + d.getDate() + '"');
    i++;
});

.each()もループであり、変数を宣言してインクリメントするだけです。

于 2013-01-21T12:46:49.390 に答える