EDIT:将标识符添加到动态生成的行中

EDIT: add an identifier to a dynamically generated row

本文关键字:动态 标识符 添加 EDIT      更新时间:2023-09-26

我正在从数据库中删除两个表。有一个Javascript函数,它将Table2中的一行添加到Table1中。我一直在尝试从confirm_trade.php页面上的Table1获取数据,这样我就可以将其放入数据库,但不知道如何提取该行(item_id)。我想把表格放在表格中可以让我通过$_POST访问它们,但这不起作用。如何向jquery行添加标识符,以便在confirm页面上抓取?

来自jQuery函数的附加行是我需要item_id的行。

function addto(obj)
{
var $row = $(obj).parents("tr");
var $table = $("#tradee");
var item_id = $row.find(".item-id").text();
var item_name = $row.find(".item-name").text();
var item_desc = $row.find(".item-desc").text();
var newTR = $("<tr><td>"+item_id+"</td><td>"+item_name+
"</td><td>"+item_desc+"</td></tr>");
$table.append(newTR);
 }     

表2:

   <div id='fixedDiv'> 
   <form action="confirm.php" method="post">        
   <table align="center" id="Table2">
    <tr><td>Other Item</td></tr>

    <?php while($rowi =$item->fetch_assoc())
    {?>
    <tr>
    <td>
        <?php echo $rowi['item_id']; ?>
    </td>
    <td>
        <?php echo $rowi['item_name']; ?>
    </td>
    <td><?php echo $rowi['item_description'];?></td>
    </tr>
    <?php } ?>
    <tr>
    <td><input type="submit" name="submit" value="Continue"/></td>
    </tr>
</table>
</form>
    </div>
    <br>

表1:

        <table align="center" id="Table1">
        <tr><th>item_id</th>
            <th>Cat_id</th>
            <th>Name</th>
            <th>Description</th>
        </tr>
    <?php while($row =$item_results->fetch_assoc())
    {?>
    <tr></tr>
    <tr>
    <td class="item-id"> <?php echo $row['item_id']; ?> </td>
    <td><?php echo $cat_id = $row['cat_id']; ?> </td>
        <td class="item-name"><?php echo $item_id = $row['item_name'];?></td>
        <td class="item-desc"><?php echo $item_descrip = $row['item_description'];?>
        </td>
        <td><input type="button" class="added" onclick="addto(this)" 
            value="Add" />
        <td><input type="button" class="removed" onclick="remove()" 
        value="Remove" >
        </td>
        </tr>
    <?php } ?>
    </table>

根据您的代码判断,您可以使用<input type="hidden" name="some_hidden_data" value="field-value">。确保你也用<form method="post"></form> 包裹你的桌子

则CCD_ 10字段将被包括为$_POST[‘hidden_field_name’];