您现在的位置: 爱51代码网 >> 范文 >> 文章正文
在js中动态添加表格行时,怎么动态改变每一行input的name值

在js中动态添加表格行时,怎么动态改变每一行input的name值

<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>

 

JavaScript code?<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;                                 //插入行                                 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;                                 } 


其中的<input type='text' id='count' name='basicBean[0].structureBeans[structurect].silkBeans[count].silkId' >structurect和count是计数,可是我这么写input的name值不会自动改变,求问我点击添加按钮,能够让新添加的行的input的name值自动递增

写个变量记录count,然后在AddStructureRowSilk方法中添加input时name的生成从变量读取

 var structurect=document.getElementById("structureCount").value;    structurect=parseInt(structurect)-1; 
  var count=document.getElementById("silkcount"+structurect).value; 
 count=parseInt(count)+1;

你不是获得这个2个变量的值了,那不就直接连接起来就好了。。

 td0.innerHTML = "<input type='text' id='count' name='basicBean[0].structureBeans["+structurect+"].silkBeans["+count+"].silkId' > ";               

  • 上一篇文章:

  • 下一篇文章: 没有了
  • 最新文章 热点文章 相关文章
    undefined reference timer_crea
    linux文件/usr/lib破坏了,还原后
    linux上运行system函数时,print
    Failed to open eth0
    android手机无法与eclipse或电脑
    C/C++洗牌算法源代码
    servlet技术实现用户名唯一的验证
    E-business suite system servic
    ZOJ 3700 Ever Dream 文章中单词
    TortoiseGit和msysGit安装及使用
    ZOJ 3700 Ever Dream 文章中单词
    TortoiseGit和msysGit安装及使用
    sharepoint 2010 获取用户信息Us
    mysql主从同步延迟方案解决的学习
    生日旅行总结
    中小板生日快乐随感
    送生日快乐桑葚乳酪小蛋糕
    写给女儿的生日快乐
    总分公司财务核算
    恢复使用繁体字可行性研究报告
    asp动态网站滚动字 如何链接
    Could not load file or ass
    asp.net线程中每隔段时间执行
    ASP.net的Button的背景色为何
    ASP.NET web打印代码
    jquery如何取指定form中的指
    MVC和三层框架的区别是什么
    asp如何判断conn对象是否为空
    如何在vb.net的winform中对于
    asp.net如何使Vector类支持I
     



    设为首页 | 加入收藏 | 网站地图 | 友情链接 |