window.onload = function() {
var oBtn = document.getElementById('btn');
oBtn.onclick = function() {
var xhr = null;
try {
xhr = new XMLHttpRequest();
} catch (e) {
xhr = new ActiveXObject('Microsoft.XMLHTTP');
}
xhr.open('get','getNews.php',true);
xhr.send();
xhr.onreadystatechange = function() {
if ( xhr.readyState == 4 ) {
if ( xhr.status == 200 ) {
//alert( xhr.responseText );
var data = JSON.parse( xhr.responseText );
var oUl = document.getElementById('ul1');
var html = '';
for (var i=0; i<data.length; i++) {
html += '<li><a href="">'+data[i].title+'</a> [<span>'+data[i].date+'</span>]</li>';//问题点:[<span>'+data[i].date+'</span>]为什么给span的外面写上[]?
}
oUl.innerHTML = html;
} else {
alert('出错了,Err:' + xhr.status);
}
}
}
}
</script>
万千封印
qq_花开花谢_0
相关分类