JS给tbale添加行 class="list" bgcolor="#ffffff" onmouseover="this.bgColor='#FFFDE2';" onmouseout="this.bgColor='#ffffff';"tr里要有这些,一起问了谢谢~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这是修改tr对象的属性问题直接赋值就好了tr.class="list";tr.bgcolor="#ffffff";tr.onmouseover="this.bgColor='#FFFDE2'";tr.onmouseout="this.bgColor='#ffffff'"; 或者用setAttribute("attribute","attributeValue")方法tr.setAttribute("class","list");…… 这是我自己写的一个表格封装类,送给你啦<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <title>无标题页</title> <script language="javascript" type="text/javascript"> function Table() { this.table=null; //表格标签 this.dataBody=null; //数据显示区 this.templet=null; //模板行 } Table.prototype.setTable=function(tableID) { this.table=document.getElementById(tableID); if(this.table!=null) { this.dataBody=this.table.children("tblDataBody"); //取得模板行 var tbody=this.table.children("tblTemplet"); this.templet=tbody.rows[0]; this.templet.style.display="none"; //将模板隐藏 } } //新增一行 Table.prototype.NewRow=function(addToTable) { //深层克隆模板行 var row=this.templet.cloneNode(true); row.style.display="block"; //设置为可见 this.AddRow(row); //加到数据显示区中 return row; //反回该行,以供编辑 } //清空表格 Table.prototype.Clear=function() { while(this.dataBody.rows.length>0) { this.dataBody.deleteRow(0); } } //删除一行 Table.prototype.DeleteRow=function(row) { this.table.deleteRow(row.rowIndex); } //以下标为参数,删除一行 Table.prototype.DeleteAt=function(index) { this.dataBody.deleteRow(index); } //将新行添加到数据显示区中 Table.prototype.AddRow=function(row) { this.dataBody.appendChild(row); } //取得所有行 Table.prototype.getRows=function() { return this.dataBody.rows; } var tbl=new Table(); window.onload=function() { tbl.setTable("tblList"); } function Test() { var row=tbl.NewRow(true); row.cells["c1"].innerHTML="newC1"; row.cells["c2"].innerHTML="newC2"; } </script></head><body> <input id="Button1" type="button" value="增加一行" onclick="Test()"/> <table id="tblList" border="1" style="border-collapse: collapse;" cellpadding="0" cellspacing="0"> <thead><tr><th>列1</th><th>列2</th></tr></thead> <!--数据区TBODY,该TBODY为空,ID指定为tblDataBody--> <tbody id="tblDataBody"> </tbody> <!--模板TBODY,该TBody有且仅有一行,ID指定为tblTemplet--> <tbody id="tblTemplet"> <tr style="cursor:pointer;"> <td id="c1">c1</td> <td id="c2">c2</td> </tr> </tbody> </table></body></html> 修正一下Table.prototype.NewRow=function(addToTable)这个函数,可以把addToTable去掉了以及var row=tbl.NewRow(true);这里把参数true去掉 你只要再在相应的位置上加上:trObj.className="样式名";就可以了 记得设置class不能obj.class="xxx"而应该obj.className="xxx" input musk 问题 innerHTML问题请教 JS高手请进来帮帮忙.. 此代码如何加上双引号或单引号? 一段JS代码,大家帮忙解释一下??谢谢! 字符串中出現單引號雙引號或括號時如何處理 倾情奉献:如何在打印时选择内容进行打印 怎样的使鼠标经过时加上声音 请问下载的BBS的代码文件怎样放在自己的asp网站中,我载的是动网的BBS js正则表达式问题 小妹遇到怪问题!!!!windows未定义!!! 在hta 里用 window.open()打开的窗口 控制大小 失效 如何处理
直接赋值就好了
tr.class="list";
tr.bgcolor="#ffffff";
tr.onmouseover="this.bgColor='#FFFDE2'";
tr.onmouseout="this.bgColor='#ffffff'";
tr.setAttribute("class","list");
……
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>无标题页</title>
<script language="javascript" type="text/javascript">
function Table()
{
this.table=null; //表格标签
this.dataBody=null; //数据显示区
this.templet=null; //模板行
}
Table.prototype.setTable=function(tableID)
{
this.table=document.getElementById(tableID);
if(this.table!=null)
{
this.dataBody=this.table.children("tblDataBody");
//取得模板行
var tbody=this.table.children("tblTemplet");
this.templet=tbody.rows[0];
this.templet.style.display="none"; //将模板隐藏
}
}
//新增一行
Table.prototype.NewRow=function(addToTable)
{
//深层克隆模板行
var row=this.templet.cloneNode(true);
row.style.display="block"; //设置为可见
this.AddRow(row); //加到数据显示区中
return row; //反回该行,以供编辑
}
//清空表格
Table.prototype.Clear=function()
{
while(this.dataBody.rows.length>0)
{
this.dataBody.deleteRow(0);
}
}
//删除一行
Table.prototype.DeleteRow=function(row)
{
this.table.deleteRow(row.rowIndex);
}
//以下标为参数,删除一行
Table.prototype.DeleteAt=function(index)
{
this.dataBody.deleteRow(index);
}
//将新行添加到数据显示区中
Table.prototype.AddRow=function(row)
{
this.dataBody.appendChild(row);
}
//取得所有行
Table.prototype.getRows=function()
{
return this.dataBody.rows;
}
var tbl=new Table();
window.onload=function()
{
tbl.setTable("tblList");
}
function Test()
{
var row=tbl.NewRow(true);
row.cells["c1"].innerHTML="newC1";
row.cells["c2"].innerHTML="newC2";
}
</script>
</head>
<body>
<input id="Button1" type="button" value="增加一行" onclick="Test()"/>
<table id="tblList" border="1" style="border-collapse: collapse;" cellpadding="0" cellspacing="0">
<thead><tr><th>列1</th><th>列2</th></tr></thead>
<!--数据区TBODY,该TBODY为空,ID指定为tblDataBody-->
<tbody id="tblDataBody">
</tbody>
<!--模板TBODY,该TBody有且仅有一行,ID指定为tblTemplet-->
<tbody id="tblTemplet">
<tr style="cursor:pointer;">
<td id="c1">c1</td>
<td id="c2">c2</td>
</tr>
</tbody>
</table>
</body>
</html>
Table.prototype.NewRow=function(addToTable)
这个函数,可以把addToTable去掉了
以及var row=tbl.NewRow(true);这里把参数true去掉
:trObj.className="样式名";
就可以了