繁体   English   中英

如何以html形式从动态字段数输入数据

[英]How To Input Data from dynamic number of fields in html form

这段代码是创建动态数量的字段并发送数据..这样做是可行的...但是然后我尝试使用back.php(form发送数据),我不知道要获取确切的数量行... id = 0_1 .... 3_1有很多选择..但是要计数成一个循环的确切数字是多少...请尽快帮助我...

<html>
    <head>
        <title>Infinite Form Rows</title>
        <script 
            type="text/javascript" 
            src="http://cachefile.net/scripts/jquery/1.2.3/jquery-1.2.3.min.js">
        </script>
        <script type="text/javascript">
        $(function(){

            var newRowNum = 0;


            $('#addnew').click(function(){

                newRowNum += 1;


                var addRow = $(this).parent().parent();

                var newRow = addRow.clone();


                $('input', addRow).val('');


                $('td:first-child', newRow).html(newRowNum);



                $('input', newRow).each(function(i){
                    var newID = newRowNum + '_' + i;
                    $(this).attr('id',newID).attr('name',newID);
                });


                addRow.before(newRow);


                $('a.remove', newRow).click(function(){
                    $(this).parent().parent().remove();
                    return false;               
                });


                return false;
            });
        });
        </script>
    </head>
    <body>
        <form action="back.php" method="get"   >
            <table id="tabdata">
                <thead>
                    <tr>
                        <th>Row</th>
                        <th>Cell 1</th>
                        <th>Cell 2</th>
                        <th>Cell 3</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td><a id="addnew" href="">Add</a></td>
                        <td><input id="n0_1" name="n0_1" type="text" /></td>
                        <td><input id="n0_2" name="n0_2" type="text" /></td>
                        <td><input id="n0_3" name="n0_3" type="text" /></td>

                        <td></td>
                    </tr>
                    <tr>

                    </tr>
                </tbody>
            </table>

            <input id="go" name="go" type="submit" value=" Save " />
        </form>
    </body>
</html>

您可以维护包含当前行数的隐藏输入。 在click事件处理程序上为#go设置值。

$('#go').click(function() {
    var numRows =$('#tabdata tbody tr').length;
    $('#myHiddenInput').val(numRows);
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM