0

查询

 <script type="text/javascript" src="jquery-1.5.1.min.js"></script>
    <script type="text/javascript">
            $('#aggiungi').live('click', function(){
            var thisRow = $(this).parent().parent();

            // clone and add data
            thisRow.clone(true).insertAfter(thisRow).data('is_clone',true);
            $(this).val("-");
            $(this).attr("id","remove");

            var nextRow = thisRow.next();
            nextRow.find('input:not(#aggiungi)').val("");

            if (thisRow.data('is_clone')){
                while(thisRow.data('is_clone')){
                    thisRow = thisRow.prev();
                }
            }else{
                nextRow.children(":first").remove();
            }

            currRowSpan = thisRow.children(":first").attr("rowspan");
            thisRow.children(":first").attr("rowspan", currRowSpan+1);
        });

        $('#remove').live('click', function(){
            var thisRow = $(this).parent().parent(),
                prevRow = thisRow.prev();

            if (thisRow.data('is_clone')){
                while(prevRow.data('is_clone')){
                    prevRow = prevRow.prev();
                }
            }else{
                prevRow = thisRow.next()
                                 .removeData('is_clone')
                                 .children(":first")
                                 .before(thisRow.children(":first"))
                                 .end();
            }

            currRowSpan = prevRow.children(":first").attr("rowspan");
            prevRow.children(":first").attr("rowspan", currRowSpan-1);
            thisRow.remove();
        });


    </script>

PHP

        <form action="grading.php" method="post">              
                              <table width-"100%" id="tableRealizzazione">
                                <tr>
                                    <th></th>
                                    <th style="padding:12px;text-align:center;">Personale</th>
                                    <th style="padding:12px;text-align:center;">Percentage</th>
                                    <th style="padding:12px;text-align:center;">Marketing point</th>
                                    <th style="padding:12px;text-align:center;">Add/Remove</th>
                                </tr>'; 

    echo '<tr class="even">
                                          <td></td>
                                          <td style="padding:12px;"><input type="text" value="" id="Personale" name="Personale"></td>
                                          <td style="padding:12px;">
                                            <input type="text" id="from" name="from" size="5%"> -
                                            <input type="text" id="to" name="to" size="5%"> %
                                          </td>
                                          <td style="padding:12px;"><input type="text" class="totaliCostiGestione" id="marketpt" name="marketpt"></td>
                                          <td style="padding:12px;"><input type="text" name="programid" value ="34" size="10%"></td>
                                          <td style="padding:12px;"><input type="button" value="+" id="aggiungi"/></td>';         
                                   echo '</tr>';
 echo '<tr><td><input type="submit" name="submit" value="submit"></td></tr>';                      
                 echo '</table>
               </form>

当我填写所有文本框的值并单击提交时,它只打印最后一行和最后一行,值为 34,其余行不重复。

这是我在小提琴 http://jsfiddle.net/gansai/PA9JF/中的代码

4

1 回答 1

1

那是因为您必须从表单中创建数组:

例如:

<input type="text" id="from" name="from[]" size="5%"> -

要克隆值,您必须添加:

newRow = thisRow.clone(true).insertAfter(thisRow).data('is_clone',true);
$(newRow+"[name^=programid]").val($(thisRow+"[name^=programid]").val());

喜欢这个JSFiddle

然后在 PHP 中:

foreach($_POST['marketpt'] as $num => $val){
    $Personale = $_POST[$num]['Personale'];
    $from = $_POST[$num]['from'];
    $to = $_POST[$num]['to'];
    $marketpt = $_POST[$num]['marketpt'];
    $programid = $_POST[$num]['programid'];
    // process variables, eg: insert in database
}
于 2012-09-21T08:23:03.410 回答