2017-04-04 55 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

回答