【问题标题】:QueryPath selector fails with chained :has():contains()QueryPath 选择器因链式 :has():contains() 而失败
【发布时间】:2014-05-08 08:19:12
【问题描述】:

以下 CSS 选择器在 jQuery 中工作,所以我希望它在 QueryPath 3.0.0 中工作,但它只返回一个空值:

div#caption:has(h2):contains('Product Description') div:first

这是我想要检索的内容:

<div id="caption"><h2>Product Description</h2><div>Text I want to capture is here.</div><div>I don't want this text.</div><br clear="all" /></div>

选择器有什么问题?

【问题讨论】:

  • 这不是一个有效的 CSS 选择器。 :has():contains():first 都是特定于 jQuery 的。这可能取决于 QueryPath 是使用 jQuery 选择器还是 CSS 选择器。
  • @BoltClock :has()、:contains() 和 :first 在大多数情况下都可以在 QueryPath 中使用。不知道为什么他们在这种情况下不这样做。

标签: php jquery-selectors css-selectors querypath


【解决方案1】:

找到原因。

:contains() 将括号视为字符串分隔符,因此您不需要在字符串周围加上引号。

如果将字符串用引号括起来,QueryPath 会查找引号。

例如,:contains('Subject') 只匹配 pcdata &lt;element&gt;'subject'&lt;/element&gt;

只需要去掉单引号,像 :contains(Product Description) 那样做。

来源:https://groups.google.com/forum/#!topic/devel-querypath/pupZjpTKyOI

【讨论】:

  • 哇,这真的很奇怪。我本来希望它可以使用或不使用引号,因为当时它已从规范中删除,it did say to accept either a string or a keyword as an argument - 根据当时的定义,这里的解决方案实际上是无效的。我想当你尝试实现一个从未完全标准化的选择器时会发生这种情况。
  • @BoltClock 我想是的。我只是希望它至少遵循 jQuery 约定并允许引号作为可选。 QueryPath 一直保持沉默,因为他们的网站出现了某种故障,所以不知道什么时候会为此修复错误。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多