jquery("foo bar")vs jquery("foo").find("bar") [英] jquery("foo bar") vs jquery("foo").find("bar")

查看:80
本文介绍了jquery("foo bar")vs jquery("foo").find("bar")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试遍历xml文档.这不起作用(零结果):

I'm trying to traverse an xml document. This doesn't work (zero results):

jquery("foo bar")

这确实有效:

jquery("foo").find("bar")

知道为什么吗?

推荐答案

jquery("foo bar")

第一个查找bar元素是foo元素的后代

the first one looks for bar element to be a descendent of foo element

因此它将在此示例中正常工作

so it would work in this example

 <foo>
  <div>Form is surrounded by the green outline</div>
  <label>Child:</label>
  <bar name="thisone" />
  <fieldset>
    <label>Grandchild:</label>
    <bar name="thisone2" />
  </fieldset>
 </foo>

这确实使用 jquery表达式

jquery("foo").find("bar")

从所有foo元素开始,并搜索后代bar元素

Starts with all foo elements and searches for descendant bar elements

因此它将在此示例中正常工作

so it would work in this example

<foo><bar>found</bar>, not here?</foo>
<foo>not here <bar>found</bar>.</foo>

因此,没有您的标记就无法真正指出您的问题

so without your markup can't really specify your problem

这篇关于jquery("foo bar")vs jquery("foo").find("bar")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆