jquery - 如何从链接直接浏览到特定评论

标签 jquery html

我希望人们在我的网站上查看最新评论,当他们点击它时,

它应该将他们带到撰写评论的业务页面,但该页面也应该向下滚动到评论所在的位置。

我在想,如果我给每个 div 指定一个不同的类名,并在类名中包含评论 ID,这可能是可能的吗? (我需要给它们相同的 id 来应用 css 格式)。

更具体地说,如何使用 jquery 直接进入 DOM review_XXX(xxx 代表评论 ID)

最佳答案

为此您不需要 jQuery。只需为链接提供一个带有 # 前缀的 href,后跟要跳转到的元素的 ID,例如:

<a href="#foo">Foo</a>
...
<div id="foo">This is the div to jump to</div>

参见"anchors with the ID attribute" in the W3C HTML Specification.

上述网站的有趣摘录:

Use id or name? Authors should consider the following issues when deciding whether to use id or name for an anchor name:

  • The id attribute can act as more than just an anchor name (e.g., style sheet selector, processing
    identifier, etc.).
  • Some older user agents don't support anchors created with the id attribute.
  • The name attribute allows richer anchor names (with entities).

另请参阅(针对 HTML5):

关于jquery - 如何从链接直接浏览到特定评论,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5539457/

相关文章:

javascript - 我怎样才能得到相对定位的 parent

javascript - 使用 remove 作为 append 的对立面不起作用

javascript - 是否有更简单的方法来引用事件的源元素?

php - 通过复选框选择无法正确删除图像

javascript - 根据显示初始 div 的链接的数据属性在鼠标悬停时显示/隐藏 div 内容

javascript - Jquery 拖放 - 在其他容器之前插入拖动的 div 容器

jquery - 快速捕获中 Unresolved 已识别错误

javascript - 操作列中的所有字符串

javascript - 粘性导航栏需要占用空间

javascript - PHP:::2 个 AJAX 调用:::2 个响应:::按顺序