3

嗨,我正在开发一个表单,当用户单击添加按钮时,它将动态生成一个表格行,但问题是我正在加载要从外部 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 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" />
4

1 回答 1

0

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

试试 $('#data').appendTo(data);

于 2013-04-15T14:50:36.807 回答