http://arstechnica.com/science/2015/01/thin-atmosphere-is-enough-to-keep-many-exoplanets-spinning/#p2如何链接到相应页面的第二段?我知道它与"#p2"有关。片段,但有问题的段落没有" p2"的ID。
在Windows 7上使用Firefox 31.0
答案 0 :(得分:1)
这当然是自定义的javascript行为。如果您好奇,请检查文件ars.min.ce8deeda61d4ec728127c4f0c17cf83e.js
。最小化它可以美化它并找到Window.onhashchange
事件处理程序,看起来像这样:
ars.setup_hashchange = function() {
var a = function() {
hash = window.location.hash.replace(/^#/, "");
if (!hash)
return;
var a = $("#" + hash + ", *[name=" + hash + "]"), b = hash.match(/^p([0-9]+)(n)?$/), c = hash.match(/^h([0-9]+)$/);
if (a.length)
ars.scroll_to(a.first());
else if (b) {
var d = $(".article-content > p")[Math.max(0, b[1] - 1)];
b[2] && (d = $(d).next()), d && ars.scroll_to($(d))
} else if (c) {
var e = $(".article-content").find("> h2, > h3, > h4").filter(":not([data-no-jump])")[Math.max(0, c[1] - 1)];
e && ars.scroll_to($(e))
}
};
$(window).on("hashchange", a), setTimeout(a, 0)
所以它从location.hash
获取段落索引,然后找到带有p
集合的相应$(".article-content > p")
元素,最后将文档滚动到它。
答案 1 :(得分:0)
这是在<article>
下,第一个<p>
是 <p class="byline" itemprop="author creator"
,第二个<p>
是您要引用的那个。搜索第一个<p>
,您将得到答案。
所以#p2
引用了第二个<p>