0

嗨,我有一个表单,当用户单击添加按钮时,它会动态生成一个表格行到目前为止,我能够生成表格行,但问题是表格中没有生成该行看看我的图片

任何人都可以帮助我这是我的脚本

 $(document).ready(function(){ 
                $('#addnew').click(function(){

                    var ctr = $('#items').val();
                    ctr++;

                    $.post('purch_srch.php', {ctr : ctr}, function(data) {
                          $(data).appendTo('#detail');

                          $('#items').val(ctr);                        
                    });
                });
            });

这是我的 php

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

$zdb = $_SESSION["zdbyear"];
mysql_select_db($zdb);

if ($_REQUEST["ctr"]){
    $ctr = $_REQUEST["ctr"];
echo "<tr>";
echo "<td>";
echo "1";
echo "</td>";
echo "<td>";
echo "2";
echo "</td>";
echo "<td>";
echo "3";
echo "</td>";
echo "<td>";
echo "4";
echo "</td>";
echo "<td>";
echo "5";
echo "</td>";
echo "<td>";
echo "6";
echo "</td>";
echo "<td>";
echo "7";
echo "</td>";
echo "</tr>";

}

这是我的html

           <table id="detail" border="1px" width="90%">
          <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>

&nbsp;<input type="button" id="addnew" class="classname" name="addnew" value="+" /> 
                  <input type="text" id="items" name="items" value="0" />  
4

2 回答 2

0

由于表格行是动态生成的,它也将具有动态 ID,并且会因机器而异。所以您将无法使用 id。

因此,如果您的行动态生成的行使用一些 class.use 类名作为选择器。

于 2013-04-16T10:36:11.823 回答
0
document.getElementById("detail").appendChild(data);

会为你工作..

于 2013-04-16T10:34:24.973 回答