【发布时间】:2015-10-05 18:04:58
【问题描述】:
我正在尝试链接到另一个页面(我无法修改)。不幸的是,该页面没有每个部分的唯一名称或 ID。相反,节标题只是在 h2 标记内。
例如:
<h2>Section A</h2>
<h2>Section B</h2>
<h2>Section C</h2>
<h2>Section D</h2>
<h2>Section E</h2>
<h2>Section F</h2>
<h2>Section G</h2>
<h2>Section H</h2>
<h2>Section I</h2>
<h2>Section J</h2>
基本上,我想将我的链接指向“F 部分”。但是,没有锚,这甚至可能吗?
【问题讨论】:
-
这在 JS 中绝对是可能的。通过某种方式找到你想要的h2标签,也许是
getElementsByTagName中的字母索引,然后确定它在页面上的位置并使用window.scrollTo。 -
@Ryan OP 甚至没有提到
id's。 -
如果您能够使用javascript来操作页面,例如访问加载到iFrame中的目标页面,那么是的,您可以。否则,您对外部页面无能为力。