• Skip to main content
  • Skip to search
  • Skip to select language

PluralsightInclude in-demand AI skills on your resume to attract recruiters and make the career moves you’ve always dreamed of.Boost your AI SkillsAd

Don't want to see ads?
MDN Web Docs
  • References
    • Overview / Web Technology

      Web technology reference for developers

    • HTML

      Structure of content on the web

    • CSS

      Code used to describe document style

    • JavaScript

      General-purpose scripting language

    • HTTP

      Protocol for transmitting web resources

    • Web APIs

      Interfaces for building web applications

    • Web Extensions

      Developing extensions for web browsers

    • Accessibility

      Build web projects usable for all

    • Web Technology

      Web technology reference for developers

  • Learn
    • Overview / MDN Learning Area

      Learn web development

    • MDN Learning Area

      Learn web development

    • HTML

      Learn to structure web content with HTML

    • CSS

      Learn to style content using CSS

    • JavaScript

      Learn to run scripts in the browser

    • Accessibility

      Learn to make the web accessible to all

  • Plus
    • Overview

      A customized MDN experience

    • AI Help

      Get real-time assistance and support

    • Updates

      All browser compatibility updates at a glance

    • Documentation

      Learn how to use MDN Plus

    • FAQ

      Frequently asked questions about MDN Plus

  • Curriculum New
  • Blog
    • Playground

      Write, test and share your code

    • HTTP Observatory

      Scan a website for free

    • AI Help

      Get real-time assistance and support

  • Log in
  • Sign up for free
  1. 面向开发者的 Web 技术
  2. XML:可扩展标记语言
  3. XPath
  4. Guides
  5. CSS 选择器与 XPath 的对比
    • Is this useful?
    • English (US)
    • Deutsch
    • Français
    • 日本語

此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

  1. XML
  2. XML Guides
    1. XML 简介
    2. 解析或序列化 XML
    3. OpenSearch 描述格式
  3. XPath
  4. Guides
    1. XPath snippets
    2. CSS 选择器与 XPath 的对比
    3. 在 JavaScript 中使用 XPath 的简介
  5. Functions
    1. boolean
    2. ceiling
    3. choose
    4. concat
    5. contains
    6. count
    7. current
    8. document
    9. element-available
    10. false
    11. floor
    12. format-number
    13. function-available
    14. generate-id
    15. id
    16. key
    17. lang
    18. last
    19. local-name
    20. name
    21. namespace-uri
    22. normalize-space
    23. not
    24. number
    25. position
    26. round
    27. starts-with
    28. string
    29. string-length
    30. substring
    31. substring-after
    32. substring-before
    33. sum
    34. system-property
    35. translate
    36. true
    37. unparsed-entity-url
  6. 轴
  7. XSLT
  8. Guides
    1. 使用 XSLT 转换 XML
    2. PI Parameters
    3. Common XSLT Errors
  9. Elements
    1. <xsl:apply-imports>
    2. <xsl:apply-templates>
    3. <xsl:attribute-set>
    4. <xsl:attribute>
    5. <xsl:call-template>
    6. <xsl:choose>
    7. <xsl:comment>
    8. <xsl:copy-of>
    9. <xsl:copy>
    10. <xsl:decimal-format>
    11. <xsl:element>
    12. <xsl:fallback>
    13. <xsl:for-each>
    14. <xsl:if>
    15. <xsl:import>
    16. <xsl:include>
    17. <xsl:key>
    18. <xsl:message>
    19. <xsl:namespace-alias>
    20. <xsl:number>
    21. <xsl:otherwise>
    22. <xsl:output>
    23. <xsl:param>
    24. <xsl:preserve-space>
    25. <xsl:processing-instruction>
    26. <xsl:sort>
    27. <xsl:strip-space>
    28. <xsl:stylesheet>
    29. <xsl:template>
    30. <xsl:text>
    31. <xsl:transform>
    32. <xsl:value-of>
    33. <xsl:variable>
    34. <xsl:when>
    35. <xsl:with-param>
  10. EXSLT
  11. Common (exsl)
    1. exsl:node-set()
    2. exsl:object-type()
  12. Math (math)
    1. math:highest()
    2. math:lowest()
    3. math:max()
    4. math:min()
  13. 正则表达式(regexp)
    1. regexp:match()
    2. regexp:replace()
    3. regexp:test()
  14. Sets (set)
    1. set:difference()
    2. set:distinct()
    3. set:has-same-node()
    4. set:intersection()
    5. set:leading()
    6. set:trailing()
  15. Strings (str)
    1. str:concat()
    2. str:split()
    3. str:tokenize()
GitLab
Start Shipping Safer SoftwareDownload GitLab’s guide to building secure software and start shipping secure software faster.Free guide
Ad
Don't want to see ads?
GitLab
Start Shipping Safer SoftwareDownload GitLab’s guide to building secure software and start shipping secure software faster.Free guide
Ad
Don't want to see ads?

CSS 选择器与 XPath 的对比

本文旨在记录 CSS 选择器和 XPath 之间的区别,以便 Web 开发人员能够更好地为正确的工作选择合适的工具。

XPath 特性 CSS 等价形式
ancestor、parent 或 preceding-sibling 轴 :has() 选择器 实验性
attribute 轴 属性选择器
child 轴 子代组合器
descendant 轴 后代组合器
following-sibling 轴 后续兄弟组合器或接续兄弟组合器
self 轴 :scope 或 :host 选择器

Help improve MDN

Learn how to contribute.

This page was last modified on 2025年2月7日 by MDN contributors.

View this page on GitHub • Report a problem with this content
GitLabAd
MDN logo

Your blueprint for a better internet.

  • MDN on Bluesky
  • MDN on Mastodon
  • MDN on X (formerly Twitter)
  • MDN on GitHub
  • MDN Blog RSS Feed

MDN

  • About
  • Blog
  • Careers
  • Advertise with us

Support

  • Product help
  • Report an issue

Our communities

  • MDN Community
  • MDN Forum
  • MDN Chat

Developers

  • Web Technologies
  • Learn Web Development
  • MDN Plus
  • Hacks Blog
  • Website Privacy Notice
  • Cookies
  • Legal
  • Community Participation Guidelines

Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2025 by individual mozilla.org contributors. Content available under a Creative Commons license.