你可以做一个hidden类型的input,记录行数
增加和删除都读这个值

解决方案 »

  1.   

    var getTb= document.getElementById("tb"); 
    var crTR = getTb.deleteRow();
      

  2.   

    var a = mm.childNode;
    if(a[a.length-1].type=="file") a[a.length-1].removeNode(true);
    if(a[a.length-2].tagName=="BR") a[a.length-2].removeNode(true);
      

  3.   

    <script>
    var addStr = "haha<br>";function add()
    {
    content.innerHTML += addStr;
    }
    function del()
    {
    var re = new RegExp(addStr+'$',"ig");
    content.innerHTML = content.innerHTML.replace(re, "");
    }
    </script><div id="content"></div>
    <input type="button" value="+" onclick="add()">
    <input type="button" value="-" onclick="del()">
      

  4.   

    <script>
    var i=0;
    function add() {
    i++;
    addStr = "<br><input name='file" + i + "' type='file' value='' size='30'>";
    content.innerHTML += addStr;
    }function del()
    {
    var o = content.childNodes;
    if(o[o.length-1].type=="file")
    o[o.length-1].removeNode(true);
    if(o[o.length-1].tagName=="BR")
    o[o.length-1].removeNode(true);
    }
    </script><div id="content"></div>
    <input type="button" value="+" onclick="add()">
    <input type="button" value="-" onclick="del()">
      

  5.   

    javascript在处理字符串时不支持"-";
    我估计你是要图形显示的效果,我想下面的这个方法可以看看;
    var cutnum=0;
    var myinnerHTML=new Array();
    function myadd(flag=1) {//标记为-1时就是减法了;
             if (flag==-1)  myinnerHTML[cutnum]="";
             else myinnerHTML[cutnum]="<br><input name='file" + cutnum + "' type='file' value='' size='30'>";
             cutnum+=flag;
    tmpinnerHTML="";
             for (n=0;0<cutnum;i++) tmpinnerHTML+= myinnerHTML[n];
             mm.innerHTML = tmpinnerHTML;
    alert(mm.innerHTML);
             return ;
    }
    function mydel(){ return myadd(-1);}
    //上面的扩展一下就可以对指定的行列操作了
      

  6.   

    + 可以连接字符串,但 - 却不能减少字符串哦,hehe.
      

  7.   

    建议楼主这样:
    <script>
    function add() {
    addStr = "<br><input name='file[]' type='file' value='' size='30'>";
    content.innerHTML += addStr;
    }function del()
    {
    var o = content.childNodes;
    if(o[o.length-1].type=="file")
    o[o.length-1].removeNode(true);
    if(o[o.length-1].tagName=="BR")
    o[o.length-1].removeNode(true);
    }</script><div id="content"></div>
    <input type="button" value="+" onclick="add()">
    <input type="button" value="-" onclick="del()"><br><br>
    取出第<input type="text" value="0" name="no">几个文件框中的值
    <input type="button" value="取值" onclick="alert(document.getElementsByName('file[]')[document.all.no.value].value)">
      

  8.   

    <script>
    var i=0;
    function add() {
    i++;
    addStr = "<br><input name='file" + i + "' type='file' value='' size='30'><input type='button' value='删除' onclick='del("+i+")'>";
    content.innerHTML += addStr;
    }function del(value)
    {
    var o = content.childNodes;
        if(o[value].type=="button")
           o[value].removeNode(true);
    if(o[value].type=="file")
           o[value].removeNode(true); 
    if(o[value].tagName=="BR")
           o[value].removeNode(true); 
    }
    </script><div id="content"></div>
    <input type="button" value="+" onclick="add()">
    <input type="button" value="-" onclick="del()">
    我自己根据 zhiin大哥的改成了这样,还是有点问题,自己搞不定了
      

  9.   

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>新建网页 1</title>
    </head>
    <body>
    <script>
    var i=0;
    function add() {
    i++;
    addStr = "<br><input name='file" + i + "' type='file' value='' size='30'><input type='button' value='删除' onclick='del("+i+")'>";
    content.innerHTML += addStr;
    }
    function del(value)
    {

    var filename="file"+value;
    var o = content.childNodes;
    for(var k=1;k<o.length;k++)
    {
    if(o[k].name==filename)
    {o[k-1].removeNode(true);  
     o[k-1].removeNode(true);
     o[k-1].removeNode(true);
     break;
    }
    }  
    }
    </script><div id="content"></div>
    <input type="button" value="+" onclick="add()">
    <input type="button" value="-" onclick="del()">
    这样OK了,原来的删除某个子对象后,总对象数会跟着改变。</body></html>
      

  10.   

    要对象个数有什么用吗?化境无组上传是以form中有多少个file识别的.
    如果非要对象总数可以这样.
    var o = content.childNodes;   
    var ocount=o.length;     //得出所有content子对象的总数
    var filecount=ocount/3; //每添加一个就加了3个子对象,用ocount/3不就得出有多少个文件数了吗?