问题一:
有一行表格,点击按钮后,再添加一行,以此类推,没有上限。(表格中含有文本域,此文本域有规律命名的,在提交列表单时,得要将这些添加进来的数据一一添加到数据库中)
问题二:
列表单添加成功后,怎么将此列表单(有可能会有多条记录)批量添加到数据库?

解决方案 »

  1.   

    用JS的insertRow和insertCell方法添加行和列,用createTextNode添加文本框,用appendChild方法把文本框添加入列
      

  2.   

    js动态创建页面元素,至于你说的命名规律可以通过检索页面上已经存在的元素来获取!不会js的话去看书!
      

  3.   

    js的话 insertRow(table1.Rows.length);
    insertCell().innerHTML=""//单元格插入内容
    jquery:
    $("#table1").find("tr:last").clone(true).appendTo($(this));
      

  4.   


    应该加上清掉最后一行表格的内容
    var temp=$("#table1").find("tr:last").clone(true);
    temp.find("td").html("");
    temp.appendTo($(this));
      

  5.   

    用JQUERY可以实现你要的效果:<script type="text/javascript">
        $(document).ready(function() {
            $("#btnDelRow").attr("disabled", true); 
            
            $("#btnAddRow").click(function() {
                $("#tabDetail tr:first").next("tr").clone().appendTo("#tabDetail");
                $("#tabDetail tr:last td input").each(function() {
                    s = $(this).attr("name");
                    i = $("#tabDetail tr").length - 2;
                    $(this).attr("name", s + i);
                });
                $("#tabDetail tr:last td select").each(function() {
                    s = $(this).attr("name");
                    i = $("#tabDetail tr").length - 2;
                    $(this).attr("name", s + i);
                });
                $("#tabDetail tr:last td input").val("")
                                                .focus(function() {
                                                    $(this).removeClass("text-input");
                                                    $(this).addClass("actived-text-input");
                                                })
                                                .blur(function() {
                                                    $(this).removeClass("actived-text-input");
                                                    $(this).addClass("text-input");
                                                }); 
                $("#btnDelRow").attr("disabled", false); 
                $("#tabDetail tr:last td input:first").focus("");
                
            });
            
            $("#btnDelRow").click(function() {
                $("#tabDetail tr:last").remove();
                $("#tabDetail tr:last td input:first").focus("");
                $(this).attr("disabled", $("#tabDetail tr").length == 2); 
            });
        });
    </script>
    <div style="float: right; marign 6px; marign-top: 4px; margin-bottom: 4px;">
        <input type="button" id="btnAddRow" value="增加行" />
        <input type="button" id="btnDelRow" value="删除行" />
    </div>
     <table id="tabDetail" style="width: 100%; margin-left: auto; margin-right: auto; margin-bottom: 4px; clear: both;">
        <tr>
            <th style="width: 160px; text-align: center"><a href="<?php echo dirname($_SERVER['SCRIPT_NAME']) . '/Return/Index/model.add' ?>">压缩机型号</a></th>
            <th style="width: 120px; text-align: center">序列号</th>
            <th style="width: 30px; text-align: center">数量</th>
            <th style="width: 180px; text-align: center"><a href="<?php echo dirname($_SERVER['SCRIPT_NAME']) . '/Return/Index/issue.kind.add' ?>">失效模式</a></th>
            <th style="text-align: center">失效描述</th>
        </tr>
        <tr>
            <td>
                <select id="cmbModel" name="cmbModel" style="width: 100%" required="true">
                    <?php
                        if (!empty($this->modelList)) {
                            foreach($this->modelList as $item) {
                                echo "<option family='" . $item["family"] . "' value='" . $item["modelName"] . "'>" . $item["modelName"] . "\n";
                            }
                        }
                    ?>
                </select>
                <!--input type="text" id="edtModel" name="edtModel" required="true" tip="请输入压缩机型号" style="width: 99%" /-->
            </td>
            <td><input type="text" id="edtSeries" name="edtSeries" required="true" tip="请输入压缩机序列号" style="width: 99%" /></td>
            <td><input type="text" id="edtQty" name="edtQty" required="true" tip="请输入数量" style="width: 96%" onKeypress="EnsureInt();" maxLength="4" value="1"/></td>
            <td>
                <select id="cmbIssueKind" name="cmbIssueKind" style="width: 100%" required="true">
                    <?php
                        if (!empty($this->issueKindList)) {
                            foreach($this->issueKindList as $item) {
                                echo "<option value='" . $item["issueKindId"] . "'>" . $item["issueKindName"] . "\n";
                            }
                        }
                    ?>
                </select>
            </td>
            <td><input type="text" id="edtIssueDesc" name="edtIssueDesc" required="true" tip="请输入失效描述" style="width: 99%" /></td>
        </tr>
    </table>