次のコード スニペットを使用して、Jquery でテーブルの tr を作成しました。
コードスニペット:
<tr>
<td class="rowcell">
<div>
<div class="intend" style="width: 24px; height: 1px; float: left;"></div>
<div class="style='float:" left'=""></div>
<div style="width: 10px; height: 1px; float: left;"></div>
<div>Task 3</div>
</div>
</td>
<td class="rowcell">
<div>01/01/2013</div>
</td>
<td class="rowcell">
<div>01/05/2013</div>
</td><td class="rowcell">
<div>5 days</div>
</td>
<td class="rowcell">
<div>77</div>
</td>
</tr>
この場合、テーブルの親のクリック イベントを呼び出しました。クリック イベントで、次のコード スニペットを使用して td の className を変更し、Selection Background を適用しましたが、この場合、ClassName は変更できません。
コードスニペット
//Here $ganttGridRows table rows.
var $ganttGridRows = $(this.getGanttGridTreeRows());
//Clicking in the row
var row = $target.closest('tr');
var index = $ganttGridRows.index(row);
var item = this.model.currentViewRange[recordIndex];
this.model.selectedRow = this.model.ganttRecords.indexOf(item);
var args = {};
if (this.model.selectedRow != -1)
args = { currentRowIndex: this.model.selectedRow, currrentRow: $ganttGridRows.eq(this.model.selectedRow), currentData: this.model.ganttRecords[this.model.selectedRow] };
if (this._trigger("rowSelecting", args))
return;
this.cleanUpSelection();
this._selectedRowsIndexes = [];
var cell = $target.closest('td');
//Here index is the rowindex of the selected row
$($ganttGridRows[index]).find('.rowcell').addClass("selectionbackground");
しかし、これは td で div を使用している間は機能しませんでした。しかし、td で div なしで使用し、以下のコード スニペットのようにテキストを直接割り当てると、問題なく動作します。
コードスニペット
<tr>
<td class="rowcell">Task 1</td>
<td class="rowcell">01/01/2013</td>
<td class="rowcell">01/05/2013</td>
<td class="rowcell">5 days</td>
<td class="rowcell">31</td>
</tr>
これを調べて、この問題を解決するための提案を提供してください。また、この動作の理由を説明してください。