返回課程

選取所有對角線儲存格

重要性:5

撰寫程式碼,將所有對角線表格儲存格塗成紅色。

您需要從 <table> 取得所有對角線 <td>,並使用程式碼將它們塗上顏色

// td should be the reference to the table cell
td.style.backgroundColor = 'red';

結果應為

開啟沙盒進行任務。

我們將使用 rowscells 屬性來存取對角線表格儲存格。

在沙盒中開啟解答。