gpt4 book ai didi

获取一个节点的 jQuery 方法——而不是 find();

转载 作者:数据小太阳 更新时间:2023-10-29 02:37:50 26 4
gpt4 key购买 nike

我已经在谷歌上搜索了一个小时,但似乎找不到答案。

我正在使用 $(xml).find('title') -- 但它似乎在所有节点中返回所有“标题”。我如何只获取根节点内的标题?

<response stat="OK">
<title>Some Document</title>
<menu>
<item>
<title>Some Title</title>
<url>/</url>
</item>
<item>
<title>Some Title 1</title>
<url>/asdfasdf/</url>
</item>
</menu>
</response>

返回“Some DocumentSome TitleSome Title 1”

// Loads the page content and inserts it into the content area
$.ajax({
dataType: 'xml',
url: 'someurl',
success: function(data, textStatus, XMLHttpRequest) {

// returns
console.log($(data).find('title').text());


}

我只想要第一个称号!我宁愿不使用 xpath,我宁愿使用最便宜的解决方案。

最佳答案

您可以使用 .children()相反,像这样:

console.log($(data).children('title').text());

.children()只查看第一层。

关于获取一个节点的 jQuery 方法——而不是 find();,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3637913/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com