我正在使用Range
andXPATH
来检索、保存和重建 html 文件中的位置。要重建范围,我正在使用document.evaluate().singleNodeValue
,问题是 singleNodeValue 在 Firefox 上返回 null,它在 chrome 上运行良好。知道为什么吗?这是我的代码:
fonction rebuildRange(xpath){
var selectionDetails = xpathh;
selectionDetails = selectionDetails.split(/\|/g);
var range = oDoc.createRange();
var selectionDetails0 = selectionDetails[0];
selectionDetails0 = selectionDetails0.replace(/\//g, "/h:");
selectionDetails0 = selectionDetails0.replace("h:t", "t");
var selectionDetails2 = selectionDetails[2];
selectionDetails2 = selectionDetails2.replace(/\//g, "/h:");
selectionDetails2 = selectionDetails2.replace("h:t", "t");
range.setStart(oDoc.evaluate(selectionDetails0, oDoc, nsResolver, 9, null).singleNodeValue, Number(selectionDetails[1]));
range.setEnd(oDoc.evaluate(selectionDetails2, oDoc, nsResolver, 9, null).singleNodeValue, Number(selectionDetails[3]));
}