Html程序  |  43行  |  1.58 KB

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="../js/resources/js-test-style.css">
<script src="../js/resources/js-test-pre.js"></script>
<script src="xpath-test-pre.js"></script>
</head>
<body>
<div id="console"></div>

<script>

var ROOT = document.createElement('div');
ROOT.innerHTML = '<p>a</p><div><span id="21"></span><span id="22"></span><span id="23"></span></div>';
var CHILD1 = ROOT.firstChild;
var CHILD1TEXT = CHILD1.firstChild;
var CHILD2 = ROOT.lastChild;
var CHILD21 = CHILD2.firstChild;
var CHILD22 = CHILD21.nextSibling;
var CHILD23 = CHILD22.nextSibling;

    result = document.evaluate(".//@id[false]", ROOT, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
    checkSnapshot("//@id[false]", result, []);

    result = document.evaluate(".//@id[1]/parent::*", ROOT, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
    checkSnapshot("//@id[1]/parent::*", result, [CHILD21, CHILD22, CHILD23]);

    result = document.evaluate(".//@id[2]/parent::*", ROOT, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
    checkSnapshot("//@id[2]/parent::*", result, []);

    result = document.evaluate(".//@id[string()='21']/parent::*", ROOT, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
    checkSnapshot("//@id[string()='21']/parent::*", result, [CHILD21]);

    result = document.evaluate(".//@id[string()='22']/parent::*", ROOT, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
    checkSnapshot("//@id[string()='22']/parent::*", result, [CHILD22]);

    var successfullyParsed = true;

</script>
<script src="../js/resources/js-test-post.js"></script>
</body>
</html>