$(document).ready(function()
{
var remote_data = [
{
'path': '/var/www/html/somefile.php',
'content': '<html><body><div class="navigation">Original data!</div></body></html>'
},
{
'path': '/var/www/html/anotherfile.php',
'content': '<html><body><div class="navigation">Original data!</div></body></html>'
}
];
var replacement = '<div class="test">New data</div>';
for (i = 0; i < remote_data.length; i++)
{
var original = $('<header>' + remote_data[i].content + '<footer>', document);
var doc = original.get();
var elems = doc.getElementsByTagName('div');
console.log(elems.length);
for (j = 0; j < elems.length; j++)
{
alert(elems[j].className);
if (elems[j].className == 'navigation')
{
alert(elems[j]);
}
}
$(original).find('.navigation').html(replacement);
document.write($(original).html());
}
});
我想打电话var elems = doc.getElementsByTagName('div');
,但这会导致错误。我不能使用 jQuery。我必须使用 javascript 从字符串中获取元素。如何才能做到这一点?