2017-05-21 4 views

答えて

0

あなたは可能性:

let table = document.getElementById('navTH') 
let numberOfElements = document.getElementsByClassName('navT').length 
table.setAttribute('colspan', numberOfElements) 
+0

[* COLSPANの*](http://www.w3.org/TR/html51/tabular-data.html#attributes-common-to-td-and- th要素)属性は[* TD *](http://www.w3.org/TR/html51/tabular-data.html#the-td-element)と[* TH *](http:// www.w3.org/TR/html51/tabular-data.html#the-th-element)の要素ではなく、[* Table *](http://www.w3.org/TR/html51/tabular-data.html #the-table-element)の要素です。 ;-) – RobG

+0

完全に同意しますが、命名規則はOPナンバーにのみ適用され、「その番号を使用してIDがnavTHのテーブルに属性colspanを持たせる」ことが求められます。私はnavTHがテーブルではなくTH要素であると仮定していますが、コードを可能な限り問題に近づけて適用するために、変数にラベル 'table'を与えました。 – kqcef

関連する問題