Php 刷新附加行中的选定选项

Php 刷新附加行中的选定选项,php,jquery,Php,Jquery,我不知道如何给这个问题正确的标题,所以很抱歉,如果这是困惑你们大家 首先,我有一个函数在表中追加一行。每一行都有一个下拉选择标记,带有我从数据库中检索到的一些选项。为了生成下拉列表,我有一个get函数,当加载页面时,我会得到一个php文件的输出,以显示下拉列表,其中包含数据库中的数据。我把它放在里面了。默认情况下,已经有3行具有相同的格式,因此我需要从头开始get。但问题是,我想在新附加行中设置下拉列表,而不刷新其他现有下拉列表。逻辑是,当我已经从现有下拉列表中选择了某个选项,然后我想添加新行,

我不知道如何给这个问题正确的标题,所以很抱歉,如果这是困惑你们大家

首先,我有一个函数在表中追加一行。每一行都有一个下拉选择标记,带有我从数据库中检索到的一些选项。为了生成下拉列表,我有一个get函数,当加载页面时,我会得到一个php文件的输出,以显示下拉列表,其中包含数据库中的数据。我把它放在里面了。默认情况下,已经有3行具有相同的格式,因此我需要从头开始get。但问题是,我想在新附加行中设置下拉列表,而不刷新其他现有下拉列表。逻辑是,当我已经从现有下拉列表中选择了某个选项,然后我想添加新行,我不想刷新已经选择的下拉列表

获取下拉功能:

$.get("getfinishlist.php", function(item) {
  $('.finish').html(item);
});
用于追加行的addrow表函数:

function addrow_table() { //#p_rows is the tbody of the table
  $('#p_rows').append("<tr><td><div align=center><input type='text' size='5' class='section' name='section[]' style='font-size:11px'></div></td>"
  +"<td><div class='desc' style='font-size:11px;'></div></td>"
  +"<td><div align=center class='finish'></div><input type='hidden' class='hfinish'></td>"
  +"<td><div align=center><input type='text' size='5' name='hrd[]' style='font-size:11px'></div></td>"
  +"<td><div align=center><input type='text' size='9' name='length[]' class='length' style='font-size:11px'></div></td>"
  +"<td><div align=center><input type='text' size='4' class='pc' name='pc[]' style='font-size:11px'></div></td>"
  +"<td><div align=center class='kg'>0</div><input type='hidden' class='hkg' name='kg[]'></td>"
  +"<td><div align=center class='price'>0</div><input type='hidden' class='hprice' name='price[]'></td>"
  +"<td><div align=center class='amount'>0</div><input type='hidden' class='hamount' name='amount[]'></td>"
  +"<td><input type='hidden' style='font-size:11px'>"
  +"<div align='center'>"
  +"<a href='#' id='delrow' style='text-decoration:none;'>"
  +"<div style='border:1px solid #a1a1a1;"
  +"background:#dddddd;"
  +"width:30px;"
  +"border-radius:5px;'>"
  +"X"
  +"</div></a></div></td>"
  +"</tr>");

  $.get("getfinishlist.php", function(item) { //I know this is wrong because every time I start the function, every dropdown refreshed
    $('.finish').html(item);
  });

  return false;
}

$('#addrow').click(function() { //#addrow is a div
  addrow_table();
});
要检索下拉列表的php文件:

<?php
  include "config/koneksi.php";
  echo "<select name='finish[]' class='sfinish'>";
  $finish = mysql_query("SELECT * FROM harga");
  while($readf = mysql_fetch_array($finish)){
    echo "<option value='".$readf['finishing']."'>".$readf['finishing']."</option>";
  }
  echo "</select>";
?>

我感谢每个人给我的每一个答案。谢谢。

在这种情况下,我认为您要做的是将ajax请求的结果设置为新添加的行

function addrow_table() { //#p_rows is the tbody of the table
    //store the added row reference in a variable - use appendTo() to return the newly added element reference
    var $row = $("<tr><td><div align=center><input type='text' size='5' class='section' name='section[]' style='font-size:11px'></div></td>" + "<td><div class='desc' style='font-size:11px;'></div></td>" + "<td><div align=center class='finish'></div><input type='hidden' class='hfinish'></td>" + "<td><div align=center><input type='text' size='5' name='hrd[]' style='font-size:11px'></div></td>" + "<td><div align=center><input type='text' size='9' name='length[]' class='length' style='font-size:11px'></div></td>" + "<td><div align=center><input type='text' size='4' class='pc' name='pc[]' style='font-size:11px'></div></td>" + "<td><div align=center class='kg'>0</div><input type='hidden' class='hkg' name='kg[]'></td>" + "<td><div align=center class='price'>0</div><input type='hidden' class='hprice' name='price[]'></td>" + "<td><div align=center class='amount'>0</div><input type='hidden' class='hamount' name='amount[]'></td>" + "<td><input type='hidden' style='font-size:11px'>" + "<div align='center'>" + "<a href='#' id='delrow' style='text-decoration:none;'>" + "<div style='border:1px solid #a1a1a1;" + "background:#dddddd;" + "width:30px;" + "border-radius:5px;'>" + "X" + "</div></a></div></td>" + "</tr>").appendTo('#p_rows');

    $.get("getfinishlist.php", function (item) {
        //find the finish element in the newly added row
        $row.find('.finish').html(item);
    });

    return false;
}

$('#addrow').click(function () { //#addrow is a div
    addrow_table();
});

好的,我会试试代码。我会很快给你反馈。非常感谢。