怎么向 一个 横行的表格中 ,插入一行,以及怎么向踪向的表格,插入一列

天限天空 2004-07-15 08:56:15
怎么向 一个 横行的表格中 ,插入一行,以及怎么向踪向的表格,插入一列
用js实现

并且要和 原来的 单元格样式一样

谢谢
...全文
205 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
lexchow 2004-07-15
  • 打赏
  • 举报
回复
横向列表
function AddColumns(tbody,columns)
{
var row=document.createElement("TR");
var col;
tbody.appendChild(row);
for(var i=0;i<columns.length;i++)
{
col=document.createElement("TD");
col.innerText=columns[i];
row.appendChild(col);
}
}
你要添加就用下面的方法,DataGrid是TBODY元素
AddColumns(DataGrid,new Array("hello","Hello","Hello","Hello"));
lexchow 2004-07-15
  • 打赏
  • 举报
回复
hooo~~~~~~~写了半天~~~按照你短信的要求,删除分类只删分类下面的东西不删除分类的标题:

function CategoryTable(Table)
{
this.Table=Table;
this.body=document.createElement("TBODY");
this.Table.appendChild(this.body);
this.Table.border ="1";
this.width="190px";
this.categoryColor="gray";
this.nameColor="silver";
this.valueColor="silver";
}
CategoryTable.prototype.AddCategory=function(caption,text)
{
var category=document.createElement("tr");
this.body.appendChild(category);
var name=document.createElement("td");
var value=document.createElement("td");
category.appendChild(name);
category.appendChild(value);
category.width=this.width;
name.width="50%";
with(value)
{
width="50%";
innerText=text;
}
category.bgColor=this.categoryColor;
name.innerText=caption;
category.tag="category";
return category;
}
CategoryTable.prototype.AddField=function(category,caption,value)
{
if(null==category)
{
throw "Parent Category Null Reference!";
}
if(category.tag!="category")
{
throw "Invalid category!";
}
var field=document.createElement("tr");
var objName=document.createElement("td");
var objValue=document.createElement("td");
objValue.bgColor=this.valueColor;
objName.bgColor=this.nameColor;
objValue.innerText=value;
objName.innerText=caption;
field.appendChild(objName);
field.appendChild(objValue);
field.tag="field";
var sibling;
if((sibling=category.nextSibling)==null)
{
this.body.appendChild(field);
}
else
{
this.body.insertBefore(field,sibling);
}
return field;
}
CategoryTable.prototype.RemoveField=function(field)
{
if(field==null)
{
throw "Null reference!";
}
if(field.tag!="field")
{
throw "Invalid field!";
}
this.body.removeChild(field);
}
CategoryTable.prototype.RemoveCategory=function(category)
{
if(category==null)
if(category.tag!="category")
{
throw "Invalid category!";
}
if(this.body.children.length<=1)
{
throw "At least one field or category must exists!";
}
var sibling=category.nextSibling;
var tmp;
while(sibling!=null)
{
if((sibling.tag=="category")||this.body.children.length<=1)
return;
tmp=sibling;
sibling=sibling.nextSibling;
this.body.removeChild(tmp);
}
}


演示代码:
var cateList=new CategoryTable(DataGrid);
var cate1=cateList.AddCategory("Hello2","f");
var category=cateList.AddCategory("Hello","f");
var field=cateList.AddField(category,"Name 1","Value");
var field=cateList.AddField(cate1,"Name 2","Value");
var field=cateList.AddField(cate1,"Name 3","Value");
// cateList.RemoveCategory(category);
你在创建实例的时候是直接绑定到某个Table上的,这样Table的样式你可以自己来弄了,这个CategoryTable有下面几个方法:
function AddCategory(caption,text) 返回一个Category
function AddField(category,caption,value) 返回一个分类下的field
function RemoveCategory(category) 删除一个分类
function RemoveField(field) 删除一个分类的field

有如下几个属性:
width 分类列表的宽,默认为190px
categoryColor分类的颜色,默认为gray
nameColor field的第一个Column的颜色,默认为silver
valueColorfield的第二个Column的颜色,默认为silver

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧