js动态向jsp中插入table,前台不报错,后台数据正常。就是不显示,这是为什么? 100
varnum=1;varlist="2017-1-1,zhangsan,xxxxxx;2017-2-5,lisi,xxxxxx;..."for(variinlist){c...
var num =1;
var list ="2017-1-1,zhangsan,xxxxxx;2017-2-5,lisi,xxxxxx;..."
for(var i in list){
console.log("i:"+list[i]);
var list2 = list[i].split(",");
var time = list2[0];
var name = list2[1];
var content = list2[2];
tr.setAttribute("width", "100%");
var td1 = document.createElement("td");
td1.setAttribute("width", "5%");
td1.innerHtml=num;
var td2 = document.createElement("td");
td2.setAttribute("width", "95%");
td2.innerHtml=time+" "+name+" 回复:"+content;
tr.appendChild(td1);
tr.appendChild(td2);
document.getElementById("msgtable").appendChild(tr);
num++;
}
list是用Split(";")分开的集合 展开
var list ="2017-1-1,zhangsan,xxxxxx;2017-2-5,lisi,xxxxxx;..."
for(var i in list){
console.log("i:"+list[i]);
var list2 = list[i].split(",");
var time = list2[0];
var name = list2[1];
var content = list2[2];
tr.setAttribute("width", "100%");
var td1 = document.createElement("td");
td1.setAttribute("width", "5%");
td1.innerHtml=num;
var td2 = document.createElement("td");
td2.setAttribute("width", "95%");
td2.innerHtml=time+" "+name+" 回复:"+content;
tr.appendChild(td1);
tr.appendChild(td2);
document.getElementById("msgtable").appendChild(tr);
num++;
}
list是用Split(";")分开的集合 展开
2个回答
展开全部
你的javascript程序有些问题,我帮你改好了,你看看吧.
<html>
<head>
</head>
<body>
<table cellpadding=1 cellspacing=1 border=1 id=msgtable>
</table>
</body>
<script type="text/javascript">
var num =1;
var list ="2017-1-1,zhangsan,xxxxxx;2017-2-5,lisi,xxxxxx";
var list1 = list.split(";");
for(var i=0;i<list1.length;i++){
console.log("i:"+list1[i]);
var list2 = list1[i].split(",");
var time = list2[0];
var name = list2[1];
var content = list2[2];
var tr = document.createElement("tr");
tr.setAttribute("width", "100%");
var td1 = document.createElement("td");
td1.setAttribute("width", "5%");
td1.innerHTML=num;
var td2 = document.createElement("td");
td2.setAttribute("width", "95%");
td2.innerHTML=time+" "+name+" 回复:"+content;
tr.appendChild(td1);
tr.appendChild(td2);
document.getElementById("msgtable").appendChild(tr);
num++;
}
</script>
</html>
运行结果
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询