java里怎样用js动态生成表格?
展开全部
<html>
<head>
<title>使用javascript动态创建表格table</title>
<SCRIPT LANGUAGE="JavaScript">
function CreateTable(disposeCount,resolveCount,remainCount){
//创建表格
var oTable = document.createElement("table");
oTable.setAttribute("border",1,0);
oTable.setAttribute("cellpadding",0,0);
oTable.setAttribute("cellspacing",0,0);
oTable.setAttribute("width","100%");
//创建Tbody
var oTBody = document.createElement("tbody");
oTable.appendChild(oTBody);
//创建 表头
var oTRHead = document.createElement("tr");
oTBody.appendChild(oTRHead);
var oTDHeadName = document.createElement("td");
oTDHeadName.appendChild(document.createTextNode("名称"));
oTRHead.appendChild(oTDHeadName);
var oTDHeadValue = document.createElement("td");
oTDHeadValue.appendChild(document.createTextNode("数量"));
oTRHead.appendChild(oTDHeadValue);
//发现数量
var oTR1 = document.createElement("tr");
oTBody.appendChild(oTR1);
var oTD11 = document.createElement("td");
oTD11.appendChild(document.createTextNode("发现数量"));
oTR1.appendChild(oTD11);
var oTD21 = document.createElement("td");
oTD21.appendChild(document.createTextNode(disposeCount));
oTR1.appendChild(oTD21);
//解决数量
var oTR2 = document.createElement("tr");
oTBody.appendChild(oTR2);
var oTD12 = document.createElement("td");
oTD12.appendChild(document.createTextNode("解决数量"));
oTR2.appendChild(oTD12);
var oTD22 = document.createElement("td");
oTD22.appendChild(document.createTextNode(resolveCount));
oTR2.appendChild(oTD22);
//剩余数量
var oTR3 = document.createElement("tr");
oTBody.appendChild(oTR3);
var oTD13 = document.createElement("td");
oTD13.appendChild(document.createTextNode("剩余数量"));
oTR3.appendChild(oTD13);
var oTD23 = document.createElement("td");
oTD23.appendChild(document.createTextNode(remainCount));
oTR3.appendChild(oTD23);
document.body.appendChild(oTable);
}
</SCRIPT>
</head>
<body onload="CreateTable(55,44,25)">
</body>
</html>
偶帮你抄一个吧。其实,网上大把。
——注明是抄的
<head>
<title>使用javascript动态创建表格table</title>
<SCRIPT LANGUAGE="JavaScript">
function CreateTable(disposeCount,resolveCount,remainCount){
//创建表格
var oTable = document.createElement("table");
oTable.setAttribute("border",1,0);
oTable.setAttribute("cellpadding",0,0);
oTable.setAttribute("cellspacing",0,0);
oTable.setAttribute("width","100%");
//创建Tbody
var oTBody = document.createElement("tbody");
oTable.appendChild(oTBody);
//创建 表头
var oTRHead = document.createElement("tr");
oTBody.appendChild(oTRHead);
var oTDHeadName = document.createElement("td");
oTDHeadName.appendChild(document.createTextNode("名称"));
oTRHead.appendChild(oTDHeadName);
var oTDHeadValue = document.createElement("td");
oTDHeadValue.appendChild(document.createTextNode("数量"));
oTRHead.appendChild(oTDHeadValue);
//发现数量
var oTR1 = document.createElement("tr");
oTBody.appendChild(oTR1);
var oTD11 = document.createElement("td");
oTD11.appendChild(document.createTextNode("发现数量"));
oTR1.appendChild(oTD11);
var oTD21 = document.createElement("td");
oTD21.appendChild(document.createTextNode(disposeCount));
oTR1.appendChild(oTD21);
//解决数量
var oTR2 = document.createElement("tr");
oTBody.appendChild(oTR2);
var oTD12 = document.createElement("td");
oTD12.appendChild(document.createTextNode("解决数量"));
oTR2.appendChild(oTD12);
var oTD22 = document.createElement("td");
oTD22.appendChild(document.createTextNode(resolveCount));
oTR2.appendChild(oTD22);
//剩余数量
var oTR3 = document.createElement("tr");
oTBody.appendChild(oTR3);
var oTD13 = document.createElement("td");
oTD13.appendChild(document.createTextNode("剩余数量"));
oTR3.appendChild(oTD13);
var oTD23 = document.createElement("td");
oTD23.appendChild(document.createTextNode(remainCount));
oTR3.appendChild(oTD23);
document.body.appendChild(oTable);
}
</SCRIPT>
</head>
<body onload="CreateTable(55,44,25)">
</body>
</html>
偶帮你抄一个吧。其实,网上大把。
——注明是抄的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询