【问题标题】:Keeping data for my new row from the database从数据库中为我的新行保留数据
【发布时间】:2014-06-08 11:11:48
【问题描述】:

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

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>

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

【问题讨论】:

  • 所有的选择都会有相同的选项吗?
  • 是的,我需要在函数追加中添加的所有选择都将具有数据库中相同的编号和相同的函数

标签: javascript php dynamic append row


【解决方案1】:

您可以像这样从第一个选择中复制选项:

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

【讨论】:

  • 如果人们想知道,谢谢在这里完美的答案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-04-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多