87,917
社区成员
发帖
与我相关
我的任务
分享
<table class="tableStyle" id="silk0">
<tr>
<%-- <td width="5%" rowspan="2" id="SilkLeft">组织丝线表</td>--%>
<td width="10%">丝线序号</td>
<td width="10%">丝线经纬</td>
<td width="10%">丝线类型</td>
<td width="10%">丝线密度</td>
<td width="10%">丝线描述</td>
</tr>
<tr id="SilkRight">
<td><input type="text" name="basicBean[0].structureBeans[0].silkBeans[0].silkId" value="<%=b0s0s0silkId%>"></td>
<td><input type="text" name="basicBean[0].structureBeans[0].silkBeans[0].silkWarpOrWeft" value="<%=b0s0s0silkWarpOrWeft%>"></td>
<td><input type="text" name="basicBean[0].structureBeans[0].silkBeans[0].silkType" value="<%=b0s0s0silkType%>"></td>
<td><input type="text" name="basicBean[0].structureBeans[0].silkBeans[0].silkDensity" value="<%=b0s0s0silkDensity%>"></td>
<td><input type="text" name="basicBean[0].structureBeans[0].silkBeans[0].silkColor" value="<%=b0s0s0silkColor%>"><input id="btnAddRow1" class="btn1"
onclick="AddStructureRowSilk()" type="button" value="+" /></td>
</tr>
</table>
<script language="javascript" type="text/javascript">
//表单操作
function AddStructureRowSilk()
{
var structurect=document.getElementById("structureCount").value; //取得添加组织结构表的个数
structurect=parseInt(structurect)-1; //转成int型
var count=document.getElementById("silkcount"+structurect).value; //实现组织参数表计数
count=parseInt(count)+1; //点击一次+1
document.getElementById("silkcount"+structurect).value=count;
var obj=document.getElementById("silk"+structurect);
var tr= obj.rows["SilkRight"];
//alert(tr.rowIndex);
//var count=document.getElementById("SilkLeft").getAttribute("rowspan");
//document.getElementById("SilkLeft").setAttribute("rowSpan",parseInt(count)+1);
//alert(count);
//document.getElementById("silkcount1").value=count;
//插入行 code form www.jb51 .net
var tr =obj.insertRow(tr.rowIndex+1);
var trId="trStructure"+tr.rowIndex;
tr.setAttribute("id",trId);
//<s:set var="ct" value="1"/>
var td0 = tr.insertCell(0);
td0.setAttribute("align","left");
td0.innerHTML = "<input type='text' id='count' name='basicBean[0].structureBeans[structurect].silkBeans[count].silkId' > ";
var td1 = tr.insertCell(1);
td1.setAttribute("align","left");
td1.innerHTML = "<input type='text' name='basicBean[0].structureBeans[structurect].silkBeans[count].silkWarpOrWeft'>";
var td2 = tr.insertCell(2);
td2.setAttribute("align","left");
td2.innerHTML = "<input type='text' name='basicBean[0].structureBeans[structurect].silkBeans[count].silkType'>";
var td3 = tr.insertCell(3);
td3.setAttribute("align","left");
td3.innerHTML = "<input type='text' name='basicBean[0].structureBeans[structurect].silkBeans[count].silkDensity'>";
var td4 = tr.insertCell(4);
td4.setAttribute("align","left");
td4.innerHTML = "<input type='text' name='basicBean[0].structureBeans[structurect].silkBeans[count].silkColor'><input id='btnDelRow' class='btn1' type='button' value='-' onclick='DelStructureRowSilk("+tr.rowIndex+")'/>";
//var input1id=document.getElementById("count").getElementsByTagName("input")[0];
//input1id.setAttribute("name","basicBean[0].structureBeans[0].silkBeans[count].silkId");
//input1id.setAttribute("id","count");
var id=document.getElementById("count").name;
document.getElementById("txt").value=id;
}
function DelStructureRowSilk1(ct)
{
var structurect=document.getElementById("structureCount").value;
structurect=parseInt(structurect)-1;
var count=document.getElementById("silkcount"+ct).value; //实现丝线表计数
count=parseInt(count)-1; //点击一次-1
document.getElementById("silkcount"+ct).value=count; //
var obj=document.getElementById("silk"+ct);
ct.parentNode.parentNode.parentNode.removeChild(ct.parentNode.parentNode);
//obj.deleteRow(rowIndex);
}
请问我想把删除也做成对应的删除,但是这样传参数没用?这里ct是一个计数,
ct.parentNode.parentNode.parentNode.removeChild(ct.parentNode.parentNode)
这样按对象删除没有效果,点击-不会删除这一行。求教,谢谢了<script language="javascript" type="text/javascript">
//表单操作
function AddStructureRowSilk()
{
var structurect=document.getElementById("structureCount").value; //取得添加组织结构表的个数
structurect=parseInt(structurect)-1; //转成int型
var count=document.getElementById("silkcount"+structurect).value; //实现组织参数表计数
count=parseInt(count)+1; //点击一次+1
document.getElementById("silkcount"+structurect).value=count;
count=count-1;
var obj=document.getElementById("silk"+structurect);
var tr= obj.rows["SilkRight"];
//alert(tr.rowIndex);
//var count=document.getElementById("SilkLeft").getAttribute("rowspan");
//document.getElementById("SilkLeft").setAttribute("rowSpan",parseInt(count)+1);
//alert(count);
//document.getElementById("silkcount1").value=count;
//插入行 code form www.jb51 .net
var tr =obj.insertRow(tr.rowIndex+1);
var trId="trStructure"+tr.rowIndex;
tr.setAttribute("id",trId);
//<s:set var="ct" value="1"/>
var td0 = tr.insertCell(0);
td0.setAttribute("align","left");
td0.innerHTML = "<input type='text' id='count' name='basicBean[0].structureBeans["+structurect+"].silkBeans["+count+"].silkId' > ";
var td1 = tr.insertCell(1);
td1.setAttribute("align","left");
td1.innerHTML = "<input type='text' name='basicBean[0].structureBeans["+structurect+"].silkBeans["+count+"].silkWarpOrWeft'>";
var td2 = tr.insertCell(2);
td2.setAttribute("align","left");
td2.innerHTML = "<input type='text' name='basicBean[0].structureBeans["+structurect+"].silkBeans["+count+"].silkType'>";
var td3 = tr.insertCell(3);
td3.setAttribute("align","left");
td3.innerHTML = "<input type='text' name='basicBean[0].structureBeans["+structurect+"].silkBeans["+count+"].silkDensity'>";
var td4 = tr.insertCell(4);
td4.setAttribute("align","left");
td4.innerHTML = "<input type='text' name='basicBean[0].structureBeans["+structurect+"].silkBeans["+count+"].silkColor'><input id='btnDelRow' class='btn1' type='button' value='-' onclick='DelStructureRowSilk(this)'/>";
//var input1id=document.getElementById("trId").getElementById("count").getElementsByTagName("input")[0];
// input1id.setAttribute("name","basicBean[0].structureBeans[0].silkBeans[count].silkId");
// input1id.setAttribute("id","count1");
var id=document.getElementById("count").name;
document.getElementById("txt").value=id;
document.getElementById("txt1").value=tr.rowIndex;
}
function DelStructureRowSilk(o)
{
var structurect=document.getElementById("structureCount").value;
structurect=parseInt(structurect)-1;
var count=document.getElementById("silkcount"+structurect).value; //实现丝线表计数
count=parseInt(count)-1; //点击一次-1
document.getElementById("silkcount"+structurect).value=count; //
var obj=document.getElementById("silk"+structurect);
o.parentNode.parentNode.parentNode.removeChild(o.parentNode.parentNode);
//obj.deleteRow(rowIndex);
}
//End
</script>
但是,我现在添加多个表之后,每个表在添加行的时候,都会点击+来调用这个js函数,这时是对最新创建的表进行操作,请问怎么才能做到我点击某一个表下面的+,只对该表进行操作,使其添加一行。这是动态添加问题,求大神解答呀 <span id=q></span>
<script language=javascript>
function z()
{
var count=document.getElementById("structureCount").value;
count=parseInt(count);
q.innerHTML=q.innerHTML+
'<table><tr><td><input type="text" name="silkCount" id="silkcount" value="1"></td></tr></table>'
+'<table class="tableStyle" id="silk0"><tr><td width="10%">丝线序号</td><td width="10%">丝线经纬</td><td width="10%">丝线类型</td><td width="10%">丝线密度</td><td width="10%">丝线描述</td></tr>'
+'<tr id="SilkRight"><td><input type="text" name="basicBean[0].structureBeans[0].silkBeans[0].silkId" ></td>'
+'<td><input type="text" name="basicBean[0].structureBeans[0].silkBeans[0].silkWarpOrWeft" ></td>'
+'<td><input type="text" name="basicBean[0].structureBeans[0].silkBeans[0].silkType" ></td>'
+'<td><input type="text" name="basicBean[0].structureBeans[0].silkBeans[0].silkDensity"></td>'
+'<td><input type="text" name="basicBean[0].structureBeans[0].silkBeans[0].silkColor"><input id="btnAddRow1" class="btn1"onclick="AddStructureRowSilk()" type="button" value="+" /></td>'
+'</tr></table>'
document.getElementById("structureCount").value=count+1;
var id=document.getElementById("silkcount0").value;
document.getElementById("txt").value=id;
}
</script>
<input value="生成表格" onclick=z() type=button>
我也设置了计数count,请问我怎么让我每次新产生的表格
<table><tr><td><input type="text" name="silkCount" id="silkcount" value="1"></td></tr></table>
它的id silkcountX,X为count计数值,怎么使用这个count?
同样的在<tr id="SilkRight"><td><input type="text" name="basicBean[0].structureBeans[0].silkBeans[0].silkId" ></td>中,怎么是silkBeans[0]中的0按count计数?谢谢了<script>
function copyTable(){
var count=document.getElementById("structureCount").value;
count=parseInt(count);
var fromtb0=document.getElementById("structure0"); //复制组织结构表
var newtb0 = fromtb0.cloneNode(true);
var fromtb1 = document.getElementById("structureparameter0");
var fromtb2=document.getElementById("silk0");
var div = document.getElementById("todiv");
var newtb1 = fromtb1.cloneNode(true);
var newtb2 = fromtb2.cloneNode(true);
newtb0.setAttribute("id","structure"+count);
div.appendChild(newtb0);
newtb1.setAttribute("id","structureparameter"+count);
newtb1.setAttribute("class","tableStyle");
div.appendChild(newtb1);
newtb2.setAttribute("id","silk"+count);
newtb2.setAttribute("class","tableStyle");
div.appendChild(newtb2);
var fromtb3=document.getElementById("structureparametercountTable0"); //为组织参数表个数计数
var newtb3=fromtb3.cloneNode(true);
newtb3.setAttribute("id","structureparametercountTable"+count);
div.appendChild(newtb3);
var inputid=document.getElementById("structureparametercountTable"+count).getElementsByTagName("input")[0];
inputid.setAttribute("id","structureparametercount"+count);
var fromtb4=document.getElementById("silkcountTable0"); //为丝线表个数计数
var newtb4=fromtb4.cloneNode(true);
newtb4.setAttribute("id","silkcountTable"+count);
div.appendChild(newtb4);
var inputid=document.getElementById("silkcountTable"+count).getElementsByTagName("input")[0];
inputid.setAttribute("id","silkcount"+count);
document.getElementById("structureCount").value=count+1;
}
function delTable(){
var count=document.getElementById("structureCount").value;
count=parseInt(count)-1;
//var counttable=document.getElementById("structureCount").value;
var delform0=document.getElementById("structure"+count); //删除组织结构表
var deldiv0=document.getElementById("todiv");
deldiv0.removeChild(delform0);
var delform1=document.getElementById("structureparameter"+count); //删除组织参数表
var deldiv1=document.getElementById("todiv");
deldiv1.removeChild(delform1);
var delform2=document.getElementById("silk"+count);
var deldiv2=document.getElementById("todiv");
deldiv2.removeChild(delform2);
var delform3=document.getElementById("structureparametercountTable"+count);//删除参数计数表
var deldiv3=document.getElementById("todiv");
deldiv3.removeChild(delform3);
var delform4=document.getElementById("silkcountTable"+count);//删除丝线计数表
var deldiv4=document.getElementById("todiv");
deldiv4.removeChild(delform4);
document.getElementById("structureCount").value=count;
}
</script>
function DelStructureRowSilk(o) {
var structurect = document.getElementById("structureCount").value;
structurect = parseInt(structurect) - 1;
var count = document.getElementById("silkcount" + structurect).value; //实现丝线表计数
count = parseInt(count) - 1; //点击一次-1
document.getElementById("silkcount" + structurect).value = count; //
var obj = document.getElementById("silk" + structurect);
o.parentNode.parentNode.parentNode.removeChild(o.parentNode.parentNode)
//obj.deleteRow(rowIndex);
}
function DelStructureRowSilk(rowIndex)
{
var structurect=document.getElementById("structureCount").value;
structurect=parseInt(structurect)-1;
var count=document.getElementById("silkcount"+structurect).value; //实现丝线表计数
count=parseInt(count)-1; //点击一次-1
document.getElementById("silkcount"+structurect).value=count; //
var obj=document.getElementById("silk"+structurect);
obj.deleteRow(rowIndex);
}