实例代码“Ctrl+/”提示“F11/ESC”全屏 返回 格式化 恢复 运行
x
 
1
<!DOCTYPE html>
2
<html>
3
    <head>
4
        <title>DOM XPath Example</title>        
5
    </head>
6
    <body>
7
        <p>This example determines if any nodes match the expression <code>employee/name</code>.</p>
8
        <script type="text/javascript">
9
            var xmldom = (new DOMParser()).parseFromString("<employees><employee title=\"Software Engineer\"><name>Nicholas C. Zakas</name></employee><employee title=\"Salesperson\"><name>Jim Smith</name></employee></employees>", "text/xml");
10
            var result = xmldom.evaluate("employee/name", xmldom.documentElement, null, XPathResult.BOOLEAN_TYPE, null);
11
12
            alert(result.booleanValue);
13
            
14
        </script>
15
 
16
 
17
    </body>
18
</html>
19