0

我尝试将行添加到表中,但这不起作用,甚至没有给出任何错误,错误在哪里?我添加了计数器变量,以便它增加 id ,以便值正确存储在数据库中

<html>
    <head>

    <%--<script type="text/javascript" src="jquery-1.3.2.min.js"></script>--%>

     <script type="text/javascript" src=" https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    </head>
    <body>
    <script type="text/javascript">
      $(document).ready(function () {
     var counter = 2;
    $("#addButton").click(function () {
     if (counter > 10) {
     alert("Only 10 rows allowed");
     return false;
    }
    $('#preq > tbody:last').append('<tr id="row'+counter+' "><td><input title="Enter Kind Of work '+counter+'" readonly="readonly" onclick="if(this.value!=''){this.value='';opendrop();}else{opendrop();}" id="other_work'+counter+'" name="other_work'+counter+'" type="text" size="30"    <?php if (isset($errors)) { echo 'value="'.htmlentities(@$_POST['other_work'+counter+'']).'"'; } ?> ></td> <td><input name="client_name'+counter+'" size="40" type="text" id="client_name'+counter+'"/></td><td><input name="firm_name'+counter+'" size="40" type="text" id="firm_name'+counter+'" />  </td>   </tr>');
      counter++;
     });

    </script>
    <table id="preq">
     <tbody>
      <tr>
    <td> 
    <input title="Enter Kind Of work 4" readonly="readonly" onclick="if(this.value!=''){this.value='';opendrop();}else{opendrop();}" id="other_work4" name="other_work4" type="text" size="30"    <?php if (isset($errors)) { echo 'value="'.htmlentities(@$_POST['other_work4']).'"'; } ?> >               
    </td>
     <td><input name="client_name4" size="40" type="text" id="client_name4"/>
    </td>
     <td><input name="firm_name4" size="40" type="text" id="firm_name4" />  </td>   
    </tr>
     </tbody>
    </table>

    <input type='button' value='Add Button' id='addButton' />

    </body>
    </html>
4

1 回答 1

2

这是您问题的答案

$("#preq tbody").append('<tr id="row"><td></td><td></td><td></td></tr>');

看看这个演示,这可能会帮助您在表格中添加行。看看这个 JQFAQ.com 并有更多的常见问题解答我希望这将帮助您获得更多的想法。

于 2013-01-04T13:31:39.833 回答