我在页面中有一些链接。我想计算每个链接的响应并在链接前面插入数字。这是我所拥有的:
var links = document.evaluate('..../td[1]/font//a[@href]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
var headings = document.evaluate('.../td[1]',document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
for(var i = 0; i < links.snapshotLength; i++){
var urls = links.snapshotItem(i).href;
GM_xmlhttpRequest({
method: 'GET',
url: urls,
onload function (res){
var dt = document.implementation.createDocumentType("html",
"-//W3C//DTD HTML 4.01 Transitional//EN", "http://www.w3.org/TR/html4/loose.dtd");
doc = document.implementation.createDocument('', '', dt);
html = doc.createElement('html');
html.innerHTML = res.responseText;
doc.appendChild(html);
var responses = doc.evaluate('.../tr', doc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
var nResponse = responses.snapshotLength - 1;
var numResponse = document.createElement('font');
numResponse.innerHTML =
'<b>' + nResponse +
'</b>' ;
headings.snapshotItem(i).parentNode.insertBefore(numResponse, headings.snapshotItem(i));
}
});
}
我收到错误消息:
类型错误:headings.snapshotItem(...) 为空