鍍金池/ 問(wèn)答/HTML/ Ajax接收數(shù)據(jù)時(shí),為什么給span的外面寫(xiě)上【】?

Ajax接收數(shù)據(jù)時(shí),為什么給span的外面寫(xiě)上【】?

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>';//問(wèn)題點(diǎn):[<span>'+data[i].date+'</span>]為什么給span的外面寫(xiě)上[]?
                }
                oUl.innerHTML = html;
            } else {
                alert('出錯(cuò)了,Err:' + xhr.status);
            }
        }
        
    }
    
}

}
</script>

回答
編輯回答
忘了我

只是html代碼,span標(biāo)簽包含在li標(biāo)簽里面而已,就像平常的< li ><span></span>< /li >寫(xiě)法,沒(méi)有其他意思

2017年9月4日 07:29
編輯回答
乖乖噠

只是想展示成[]的格式,和別的沒(méi)有關(guān)系

2018年4月13日 11:49
編輯回答
擱淺

就是單純的方括號(hào)呀

2017年4月30日 18:28
編輯回答
單眼皮

這與ajax沒(méi)有半毛錢(qián)關(guān)系。

拿到數(shù)據(jù)想展示成標(biāo)題[yyyy-MM-dd]而已

2017年10月26日 01:07
編輯回答
安若晴

這個(gè)只是字符串,和ajax沒(méi)關(guān)系!應(yīng)該是你們產(chǎn)品經(jīng)理的要求data[i].date需要包裹[],你可以 刪掉[] 或者 新增 [] 看看頁(yè)面是不是也相應(yīng)的發(fā)生變化!

2017年11月11日 16:50
編輯回答
遺莣

這只是字符串,和ajax沒(méi)關(guān)系,寫(xiě)不寫(xiě)都可以。

2018年4月9日 00:08