从数据库中保留新行的数据

Keeping data for my new row from the database

本文关键字:数据 新行 保留 数据库      更新时间:2023-09-26

我有一个添加新行的按钮。但是,当我为我的新行选择时,它是空的。我真的不知道如何像我原来的那一排那样填满它。

JavaScript/jQuery代码:

var counter = 0;
var $newRow ; 
$(function(){
    $('#add_field').click(function(){
        counter += 1;
        $('#tache').append('<select id="tache' + counter + '" name="tache[]' + '" type="text"  />');
    });
});

这里是我原始行的一个例子,我如何填写我的选择。

<!-- tache  -->
<td>
    <span id="tache">
    <!-- dꣵt section combobox tache avec tool tip -->
    <label title="Selectdimanche">
        <select title="Selectdimanche" id="Selectdimanche" name="Selectdimanche">
        <?php
        $stmt->execute();
        while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
            echo ' <option title="';
            echo $row['tacName'];
            echo '">';
            echo $row['tacId'];
            echo '</option>'."'n";
            $task = array();
         }
         ?>
         </select>
      </label>
     <!-- Fin section cobobox tache avec tool tip -->
    </span>
</td>

那么,我如何为我的新行填充数据呢?

您可以复制第一次选择的选项,如下所示:

var counter = 0;
$('#add_field').click(function()
{
  counter += 1;
  var select = $('<select id="tache' + counter + '" name="tache[]" type="text"  />');
  select.append($("#Selectdimanche option").clone());
  $("#tache").append(select);
});

示例:jsFiddle