2017-04-04 54 views
0

我查询以下HTML内容查询在Chrome HTML嵌入元素返回匿名函数

<html lang="en"> 
    <body> 
     <embed id="embed1" src="../support/test3.mp3" autostart="true" style="width:150px; height:150px" alt="fish"> 
      <noembed id="noembed1">Sound of a fish</noembed> 

     <embed id="embed1a" src="../support/test3.mp3" autostart="TRUE" style="width:150px; height:150px" alt="fish"> 
      <noembed id="noembed1a">Sound of a fish</noembed> 

    </body></html> 

与以下XPath查询

var nodes = document.evaluate("/html[1]/body[1]/embed[1]", document, null, XPathResult.ANY_TYPE, null); 
var node = nodes.iterateNext(); 
console.log(node); 

这将返回匿名函数。

function anonymous() 

但是其中火狐返回嵌入元件。

如何获取chrome中的嵌入节点?

+0

为什么试图使用'XPath'?您可以简单地使用'var nodes = document.getElementById(“embed1”);' – Andersson

+0

因为我只有XPATH由其他组件返回。我需要使用XPATH访问元素,以便我可以对其执行其他操作。 – surya

+0

其实你的代码应该返回所需的web元素,而不是一个函数。你从哪里得到这个'XPath'? – Andersson

回答