如何使用jquery从外部php文件对齐动态生成的表行

时间:2022-02-14 01:14:40

hi i have a form which dynamically generate a table row when user clicks on the add button so far i am able to generate the table row but the problem is the the row is not being generated in form 如何使用jquery从外部php文件对齐动态生成的表行

您好我有一个表单,当用户点击添加按钮时动态生成一个表行,到目前为止,我能够生成表行,但问题是没有在表单中生成行

can anybody help me in this here is my script

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

 $(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);                        
                    });
                });
            });

here is my php

这是我的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>";

}

here is my html

这是我的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" />  

2 个解决方案

#1


0  

document.getElementById("detail").appendChild(data);

would work for you..

会对你有用..

#2


0  

As the table row is generated dynamically it will also have dynamic id and will vary machine to machine.so u wont be able to use id.

由于表行是动态生成的,它也会有动态ID,并且会因机器而异。所以你不能使用id。

So if Your row dynamically generated row use some class.use class name as selector.

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

#1


0  

document.getElementById("detail").appendChild(data);

would work for you..

会对你有用..

#2


0  

As the table row is generated dynamically it will also have dynamic id and will vary machine to machine.so u wont be able to use id.

由于表行是动态生成的,它也会有动态ID,并且会因机器而异。所以你不能使用id。

So if Your row dynamically generated row use some class.use class name as selector.

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