使用JS,如何动态生成表格及表格中的按钮

wljsp 2006-02-27 07:06:42
我不会写JS.
有一个字符串在VB中是以 chr(0) ,为分隔符的。
例如字符串是:C:\temp\a.jpg chr(0) b.jpg chr(0) c.jpg

在HTML网页上,有一个表格 tbFile 是2列的,第一列是文件名,第二列是 button 按钮。
如何将这个字符串中的文件名取出,每一个文件名增加一行,第一列是文件名,第二列是 button 按钮?

如何分解这个字符串? 如何动态的增加 button 按钮?
...全文
832 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
wljsp 2006-03-02
  • 打赏
  • 举报
回复
多谢各位,已编写成功了!
特别感谢! mingxuan3000
mingxuan3000 2006-03-01
  • 打赏
  • 举报
回复
<table width="200" height="54" border="1" align="center" id="iTab">
<tr id="tr0">
<td>
<input name=chk_1 type=checkbox id=chk_1 value="1" />
</td>
<td>0</td>
</tr>
</table>

<input type="button" name="Submit" value="123" onclick="addTR()" />
mingxuan3000 2006-03-01
  • 打赏
  • 举报
回复
function addTR()
{


var iTab = document.getElementById("iTab");


iTab.rows[0].cells[1].innerHTML="<td><input name=chk_1 type=button id=chk_1 value='1' /></td>";


}
mingxuan3000 2006-03-01
  • 打赏
  • 举报
回复
<table width="200" height="54" border="1" align="center" id="iTab">
<tr id="tr0">
<td>
<input name=chk_1 type=checkbox id=chk_1 value="1" />
</td>
<td>0</td>
</tr>
</table>

<input type="button" name="Submit" value="123" onclick="addTR()" />




function addTR()
{
alert(iTab);

var iTab = document.getElementById("iTab");
alert(iTab);

var iTr = iTab.insertRow();

var cellNum = iTr.insertCell();;

//for (colIndex = 0; colIndex < cellNum; colIndex++)
//{
//var newCell = iTr.insertCell();
//
cellNum.innerHTML="<td><input name=chk_1 type=checkbox id=chk_1 value='1' /></td>";
//全插进一格里去啦.如果分开写,比如说在第一格插什么,在第二格在插什
//}
alert(iTr);
alert(iTab.rows[0].cells[1]);
alert('123');
iTab.rows[0].cells[1].innerHTML="<td><input name=chk_1 type=button id=chk_1 value='1' /></td>";
alert('456');

}
wljsp 2006-03-01
  • 打赏
  • 举报
回复
多谢! 我试试看。

并感谢 mingxuan3000(铭轩) 的短信回复!
happilygirl 2006-03-01
  • 打赏
  • 举报
回复
是双引号的问题,你把双引号改成单引号看看。
wljsp 2006-02-28
  • 打赏
  • 举报
回复
需要定义一个 button 按钮,增加到 第2列上?
如何定义? 如何增加?
wljsp 2006-02-28
  • 打赏
  • 举报
回复
多谢各位,特别是 mingxuan3000(铭轩) 写得很详细
我试试先。
valenwon 2006-02-28
  • 打赏
  • 举报
回复
var newl,newc;
newl=table的id.insertRow();
newc=newl.insertCell();
newc.innerHTML="你要插入html代码";
这样就可以了。
yiyioo 2006-02-28
  • 打赏
  • 举报
回复
请参考DHTML
创建元素createElement
表格有table.insertRow();
行有tr.insertCell();
.....
wljsp 2006-02-28
  • 打赏
  • 举报
回复
var btnHtml ="<input type=button name=\"aa\" onclick=aa(\"a\") id=\"aa\"/>";
cell.innerHtml = btnHtml;

我这样写,为什么不显示? 没有错误提示,就是不显示按钮。
mingxuan3000 2006-02-28
  • 打赏
  • 举报
回复
tableId.rows[0].cells[1]innerHTML="<input type=button name="aa" onclick=""/>"
mingxuan3000 2006-02-27
  • 打赏
  • 举报
回复
chr(0)这个不知道,用split分割字符串
mingxuan3000 2006-02-27
  • 打赏
  • 举报
回复
function addRow(){
var tblObj = document.getElementById("table1");
if(tblObj.rows){
alert(tblObj.rows.length);
}else{
alert('aaa');
}
//追加行
var newRow = tblObj.insertRow();
newRow.style.display = "";
var cellNum = tblObj.rows[0].cells.length;

//追加列
for (colIndex = 0; colIndex < cellNum; colIndex++) {
var newCell = newRow.insertCell();
initTblCell(newCell);
}
}
function initTblCell(cell){
var lastCell = document.getElementById("table1").rows[0].cells[cell.cellIndex];
cell.innerHTML = lastCell.innerHTML;
alert(cell.innerHTML);
if (cell.children != null && cell.children.length > 0) {
for(childIndex = 0; childIndex < cell.children.length; childIndex++) {
var child = cell.children[childIndex];
switch(child.type) {
case "text":
child.value = "";
break;
case "checkbox":
child.value = "";
child.checked = false;
break;
}
}
}
cell.className = lastCell.className;
cell.align = lastCell.align;
cell.height = lastCell.height;
}
function buttonFun(){
var obj= document.getElementsByName("text4");
for(i=1;i<obj.length;i++){
alert(obj[i].value);
}

}
function dellRow(){
var obj= document.getElementById("table1");
var objRow=obj.rows.length-1;
alert(objRow);
if(objRow != 0){
obj.deleteRow(objRow);
}

}



<table id="table1" name="table1" width="300">
<tr style="display:none">
<td width="100">
<input type="button" name="testBtn4" value="button" onclick=""/>
</td>
<td width="100">
<input type="text" name="text4" id="text4"/>
</td>
<td width="100">
123
</td>
</tr>

<tr>
<td width="100">
<input type="button" name="testBtn4" value="button" onclick="toExcel_Page()"/>
</td>
<td width="100">
<input type="text" name="text4" id="text4"/>
</td>
<td width="100">
123
</td>
</tr>
</table>
<input type="button" name="testAdd" id="testAdd" value="AddRow" onclick="addRow()"/>
<input type="button" name="testAdd" id="testAdd" value="DellRow" onclick="dellRow()"/>
<input type="button" name="testAdd2" id="testAdd2" value="GetTextValue" onclick="buttonFun()"/>

87,901

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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