gpt4 book ai didi

php - 当行内容来自数据库时,单击按钮动态添加表行

转载 作者:搜寻专家 更新时间:2023-10-31 22:07:51 25 4
gpt4 key购买 nike

您好,我正在开发一个表单,当用户单击添加按钮时,该表单将动态生成一个表格行,但问题是我正在加载要从外部 php 文件生成的行,但它似乎不起作用我我正在使用外部文件,因为该行将包含一个组合框,它将由 mysql 数据填充,任何人都可以帮助我吗这是我的脚本

$(document).ready(function() {
//var currentItem = $('#items').val();
$('#addnew').click(function(){
var ctr = $('#items').val();
ctr++;
$.post('purch_srch.php', {ctr : ctr}, function(data) {
$(data).appendTo('#data')
$('#items').val(ctr);
});
});
});

这是我的php

<?php
session_start();

require("includes/dbconnect.php");
include ('includes/function.php');

mysql_select_db($_SESSION["zdbname"]);

if (isset($_POST['ctr'])) {
$ctr = $_POST['ctr'];

echo '<tr>';

echo '<td align="center"><input type="text" size="6" maxlength="6" maxlength="6" name="ord_'.$ctr.'" class="form-input-oth"/></td>';
echo "<td>";
echo '<select data-placeholder="Party" style="width:120px;" name="item_'.$ctr.'" class="chzn-select-deselect" >';
echo "<option value = '' ></option>";
$get = mysql_query("SELECT * FROM accmast WHERE `grpcode`='010'") or die(mysql_error());
while($cc = mysql_fetch_array($get)){
echo "<option value=$cc[accode]>$cc[name]</option>";
}
echo "</select></td>";
echo '<td align="center"><input type="text" size="6" maxlength="9" maxlength="6" name="descrip_'.$ctr.'" class="form-input-name"/></td>';
echo '<td align="center"><input type="text" size="6" maxlength="9" maxlength="6" name="unit_'.$ctr.'" class="form-input-rate"/></td>';
echo '<td align="center"><input type="text" size="6" maxlength="9" maxlength="6" name="totqty_'.$ctr.'0" class="qty form-input-rate"/></td>';
echo '<td align="center"><input type="text" size="6" maxlength="9" maxlength="6" name="rate_'.$ctr.'" class="rate form-input-rate"/></td>';
echo '<td align="center"><input type="text" size="6" maxlength="9" maxlength="6" name="amt_'.$ctr.'" class="cal form-input-amt"/></td>';
echo "</tr>";
}
else{
echo "ERROR";
}

这是我的 table

<table border="1px" width="90%" id="data">
<tr>
<td><br /></td>
</tr>
<tr>
<td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Order</font><span></span></label></td>
<td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">item</font><span></span></label></td>
<td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Description</font><span></span></label></td>
<td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Unit</font><span></span></label></td>
<td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Total Quantity</font><span></span></label></td>
<td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Rate</font><span></span></label></td>
<td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Amount</font><span></span></label></td>
</tr>
<tr>
<td align="center"><input type="text" size="6" maxlength="6" maxlength="6" name="ord_0" class="form-input-oth"/></td>
<td align="center">
<select data-placeholder="Party" style="width:120px;" name="order" class="chzn-select-deselect" >
<option>rehan</option>
</select>
</td>
<td align="center"><input type="text" size="6" maxlength="9" maxlength="6" name="descrip_0" class="form-input-name"/></td>
<td align="center"><input type="text" size="6" maxlength="9" maxlength="6" name="unit_0" class="form-input-rate"/></td>
<td align="center"><input type="text" size="6" maxlength="9" maxlength="6" name="totqty_0" class="qty form-input-rate"/></td>
<td align="center"><input type="text" size="6" maxlength="9" maxlength="6" name="rate_0" class="rate form-input-rate"/></td>
<td align="center"><input type="text" size="6" maxlength="9" maxlength="6" name="amt_0" class="cal form-input-amt"/></td>
</tr>
<input type="button" id="addnew" class="classname" name="addnew" value="+" />
<input type="hidden" id="items" name="items" value="1" />

最佳答案

你确定吗?$(data).appendTo('#data') ??

试试看$('#data').appendTo(数据);

关于php - 当行内容来自数据库时,单击按钮动态添加表行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16017006/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com