post提交到后台后,遍历input个数。

解决方案 »

  1.   

    1楼  。
    要是用遍历,还需要判断 。不如直接hidden保存
      

  2.   

    原理:
    提交前得到 titleconn 中的 input 数量,然后修改 hidenumber 的值
    在后台可以通过 hidenumber 的值,来判断有几个控件另外add_like()调用失败,自己写了一个<script>
    function add_like(){
    var array = document.getElementById("titleconn").getElementsByTagName("input");
    var maxnum = 0;
    for(var i = 0;i < array.length;i++){
    var crtnum = parseInt(array[i].name.replace("title",""));
    maxnum = maxnum < crtnum ? crtnum : maxnum;
    }
    document.getElementById("titleconn").innerHTML += "<tr><td id='td11'><input name='title" + (maxnum + 1) + "' type='text' class='class1' /></td></tr>";
    }function formSubmit(){
    var array = document.getElementById("titleconn").getElementsByTagName("input");
    document.getElementById("hidenumber").value = array.length;
    alert(document.getElementById("hidenumber").value);
    document.form1.submit();
    }
    </script><form name="form1" method="post" action="" onSubmit="return checkForm();">
    <input name="hidenum" type="hidden" value="0" id="hidenumber"/>
    <span id="titleconn">
    <tr><td id="td11"><input name="title1" type="text" class="class1" /></td></tr>
    <tr><td id="td11"><input name="title2" type="text" class="class1" /></td></tr>
    <tr><td id="td11"><input name="title3" type="text" class="class1" /></td></tr>
    </span>
    <tr>
    <td cols="*"><a onClick="add_like()" href="#">+增加一栏</a></td>
    </tr>
    <tr>
    <td cols="*"><input type="button" onClick="formSubmit()" value="提交"></td>
    </tr>
    </form>