JavaScript: iterating over document.evaluate() XPathResult returns null

丶灬走出姿态 提交于 2019-12-25 14:49:10

问题


I am trying to get all objects but it doesn't work.

var tmp = document.evaluate("//tr", document, null, XPathResult.ANY_TYPE, null);

tmp.iterateNext returns me null;


回答1:


If you are working in IE, then you should know that document.evaluate does not exist there (see this similar question and the last couple of paragraphs here).

Why not just document.getElementsByTagName("tr");?




回答2:


In my opinion, using an existing JS libraries such as JQuery is usually more reliable in cases like this.




回答3:


document.getElementsByTagName("tr"); 

It also will not work, because IE some versions doesn't support this method for elements, which has not such attribute like 'name'.



来源:https://stackoverflow.com/questions/1934019/javascript-iterating-over-document-evaluate-xpathresult-returns-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!