zoukankan      html  css  js  c++  java
  • js为表格添加行和列

    <table id="studentTable" align="center" border="1px;" cellpadding="0px;">
    <tr>
    <th>姓名</th><th>年龄</th><th>得分</th>
    </tr>
    </table>

    function loadInfo2(){
    var xmlHttp;
    if(window.XMLHttpRequest){
    xmlHttp=new XMLHttpRequest();
    }else{
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlHttp.onreadystatechange=function(){
    if(xmlHttp.readyState==4 && xmlHttp.status==200){
    alert(xmlHttp.responseText);
    var dataObj=eval("("+xmlHttp.responseText+")");
    var st=document.getElementById("studentTable");
    alert(dataObj.students.length);
    var newTr; // 行
    var newTd0; // 第一列
    var newTd1; // 第二列
    var newTd2; // 第三列
    for(var i=0;i<dataObj.students.length;i++){
    var student=dataObj.students[i];
    newTr=st.insertRow();
    newTd0=newTr.insertCell();
    newTd1=newTr.insertCell();
    newTd2=newTr.insertCell();
    newTd0.innerHTML=student.name;
    newTd1.innerHTML=student.age;
    newTd2.innerHTML="语文:"+student.score.chinese+",数学:"+student.score.math+",英语:"+student.score.english;
    }
    }
    };
    // xmlHttp.open("get", "getAjaxInfo?action=jsonArray", true);
    xmlHttp.open("get", "getAjaxInfo?action=jsonNested", true);
    xmlHttp.send();
    }

  • 相关阅读:
    javascript基础
    杂谈
    六大设计原则
    MVC的理解
    不错的资源哦
    平时你从哪里获取前端知识?
    网站背景平铺
    js 获取节点
    自适应后的页面用户点击后会放大
    innerHTML的运用
  • 原文地址:https://www.cnblogs.com/luoxiaolei/p/5128843.html
Copyright © 2011-2022 走看看