Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/423.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 通过xpath从节点中查找子节点_Javascript_Jquery - Fatal编程技术网

Javascript 通过xpath从节点中查找子节点

Javascript 通过xpath从节点中查找子节点,javascript,jquery,Javascript,Jquery,我需要检查一些字段并打印文本。但是,我找不到一个函数可以输出给定节点的子节点和该子节点的xpath 在下面的代码片段中,我使用了不存在的函数“getSubnode”。如果有人能给我一个如何实施的提示,我将不胜感激 x = $('div.content'); for (i=0; i<x.length; i++) { y1 = getSubnode(x[i], "span/strong"); y2 = getSubnode(x[i], "a/strong"); cons

我需要检查一些字段并打印文本。但是,我找不到一个函数可以输出给定节点的子节点和该子节点的xpath

在下面的代码片段中,我使用了不存在的函数“getSubnode”。如果有人能给我一个如何实施的提示,我将不胜感激

x = $('div.content');
for (i=0; i<x.length; i++) {
    y1 = getSubnode(x[i], "span/strong");
    y2 = getSubnode(x[i], "a/strong");
    console.log(y1.textContent, y2.textContent)
}
x=$('div.content');

对于(i=0;ithat函数将返回一个数组而不是单个node@guido,这很有意义。您是否有一个示例,说明如何实现类似于getSubnode()的功能并返回一个节点列表?我不清楚您想做什么,但是要选择的节点的xpath是
//div[@class='content']//span/strong |//div[@class='content']//a/strong
@guido对不起,我的问题说得不够清楚。我需要从节点开始执行XPath,而不是从根开始。