JavaScript:XPathEvaluator不支持IE [英] JavaScript : XPathEvaluator not supported in IE

查看:830
本文介绍了JavaScript:XPathEvaluator不支持IE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 JavaScript 中具有以下功能,并且在使用 Internet Explorer 时无法运行。

I have the following function in JavaScript, and it fails to run when using Internet Explorer.

此函数从 HTML标签中提取值,如果 XPath 提供。

This function extract the value from a HTML tag, if a XPath is supplied.

我如何替换此功能,以及什么?

How can i replace this function, and with what ?

function lookupElementByXPath(path) {
    var evaluator = new XPathEvaluator(); 
    var result = evaluator.evaluate(path, document.documentElement, null,XPathResult.FIRST_ORDERED_NODE_TYPE, null); 
    return result.singleNodeValue;
}


推荐答案

Internet Explorer是唯一的浏览器现在不支持 XPathEvaluator 。您可以在DOM Document对象上使用 selectNode() selectSingleNode()(仅限IE)。

Internet Explorer is the only browser that now doesn't support XPathEvaluator. You can use selectNode() and selectSingleNode() on the DOM Document object instead (IE only).

这篇关于JavaScript:XPathEvaluator不支持IE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆