14,953
edits
m (→Approach 2) |
|||
| Line 35: | Line 35: | ||
* If the table contains the <tbody> tag. Key in the following code to console. | * If the table contains the <tbody> tag. Key in the following code to console. | ||
<pre> var tableId = "tableId"; | <pre> var tableId = "tableId"; | ||
var rows = document.getElementById(tableId).getElementsByTagName("tr").length; | var rows = document.getElementById(tableId).getElementsByTagName("tr").length; | ||
console.log("rows count of table which contains heading: " + rows); | console.log("rows count of table which contains heading: " + rows); | ||
</pre> | </pre> | ||
* And press the {{kbd | key =<nowiki>Enter</nowiki>}} key to get the rows of table. | * And press the {{kbd | key =<nowiki>Enter</nowiki>}} key to get the rows of table. | ||
| Line 48: | Line 48: | ||
* 如果網頁表格包含 <tbody> tag,在 chrome 開發者工具的 console 輸入 | * 如果網頁表格包含 <tbody> tag,在 chrome 開發者工具的 console 輸入 | ||
<pre> var tableId = "tableId"; | <pre> var tableId = "tableId"; | ||
var rows = document.getElementById(tableId).getElementsByTagName("tbody")[0].getElementsByTagName("tr").length; | |||
console.log("不包含表頭那一行的資料列數: " + rows); | |||
</pre> | </pre> | ||
* 按 {{kbd | key =<nowiki>Enter</nowiki>}},取得資料列數 | * 按 {{kbd | key =<nowiki>Enter</nowiki>}},取得資料列數 | ||
| Line 55: | Line 55: | ||
* 如果網頁表格不包含 <tbody> tag.,在 chrome 開發者工具的 console 輸入 | * 如果網頁表格不包含 <tbody> tag.,在 chrome 開發者工具的 console 輸入 | ||
<pre> var tableId = "tableId"; | <pre> var tableId = "tableId"; | ||
var rows = document.getElementById(tableId).getElementsByTagName("tr").length; | var rows = document.getElementById(tableId).getElementsByTagName("tr").length; | ||
console.log("包含表頭那一行的資料列數: " + rows); | console.log("包含表頭那一行的資料列數: " + rows); | ||
</pre> | </pre> | ||
* 按 {{kbd | key =<nowiki>Enter</nowiki>}},取得資料列數 | * 按 {{kbd | key =<nowiki>Enter</nowiki>}},取得資料列數 | ||
== References == | == References == | ||