从特定 Div JS 加载元素



我需要做的是仅从名为megaContent的div加载第二个表(或tbody)元素(未命名且没有类)。我打算做的是让浏览器转到页面,然后加载此 JS 并让它仅显示该部分。

"

仅加载表"是什么意思并不完全清楚。 如果您只想显示表并且由于它没有任何类或 id 而不知道如何访问它,您可以执行以下操作:

var tbls = document.getElementById("megaContent").getElementsByTagName("table");
var tbl = tbls[0]; // [0] if the desired table is the first table in that div, [1] if second etc.
tbl.style.display="block"; //or "table", or whatever you'd like to do with that table.

希望这有帮助。

最新更新