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>
添加回答
举报
0/150
提交
取消