Codeigniter Addrow不工作

时间:2016-08-24 11:03:36

标签: php html codeigniter

我正在使用codeigniting base,但似乎脚本无效。 点击+按钮时没有任何事情发生。我在网站上找到了这个脚本。我希望有人可以帮助我:D,非常感谢Dennis

 <div class="row"><br/>
    <div class="container" style="background-color:#e3e3e3">
      <center><h1>Information Product</h1></center>

      <form action="<?= site_url('product/save') ?>" method="post">
        <table class="table">
                <tr>
                    <td>
                        <label>Title</label>
                        <input type="text"  class="form-control" name="title">
                    </td>
                </tr>
        </table>
        <input type="submit" value="Submit" class="btn btn-primary">
        <table class="table table-borderd table-hover">
            <thead>
                <tr>
                    <th>ProductName</th>
                    <th>Quantity</th>
                    <th>Price</th>
                    <th><input type="button" class="btn btn-primary addrow" id="addrow" value="+"></th>
                </tr>
            </thead>
            <tbody class="detail">
                <tr>
                    <td><input type="text" name="product_name[]" class="form-control"></td>
                    <td><input type="text" name="quantity[]" class="form-control"></td>
                    <td><input type="text" name="price[]" class="form-control"></td>
                    <td><a href="#" class="remove">Remove</a></td>
                </tr>
            </tbody>
        </table>
      </form>

    </div>
</div>

<script type="text/javascript">
$(function(){
    $('.addrow').click(function(){
        var tr = '<tr>'+
                    '<td><input type="text" name="product_name[]" class="form-control"></td>'+
                    '<td><input type="text" name="quantity[]" class="form-control"></td>'+
                    '<td><input type="text" name="price[]" class="form-control"></td>'+
                    '<td><a href="#" class="remove">Remove</a></td>'+
                '</tr>';
        $('.detail').append(tr);
    });

    $('body').delegate('.remove','click',function(){
        var tr = $(this).parent().parent();
        var c = confirm("Do you want to remove this ?");
        if(c)
        {
            tr.remove();
        }
    });
});

1 个答案:

答案 0 :(得分:1)

   <div class="row"><br/>
   <div class="container" style="background-color:#e3e3e3">
   <center><h1>Information Product</h1></center>

  <form action="<?= site_url('product/save') ?>" method="post">
    <table class="table">
            <tr>
                <td>
                    <label>Title</label>
                    <input type="text"  class="form-control" name="title">
                </td>
            </tr>
    </table>
    <input type="submit" value="Submit" class="btn btn-primary">
    <table class="table table-borderd table-hover">
        <thead>
            <tr>
                <th>ProductName</th>
                <th>Quantity</th>
                <th>Price</th>
                <th><input type="button" class="btn btn-primary addrow" id="addrow" value="+"></th>
            </tr>
        </thead>
        <tbody class="detail">
            <tr>
                <td><input type="text" name="product_name[]" class="form-control"></td>
                <td><input type="text" name="quantity[]" class="form-control"></td>
                <td><input type="text" name="price[]" class="form-control"></td>
                <td><a href="#" class="remove">Remove</a></td>
            </tr>
        </tbody>
    </table>
  </form>

</div>
</div>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.js" type="text/javascript"></script>
 <script type="text/javascript">
  $(function(){
  $('.addrow').click(function(){
      var tr = '<tr>'+
                '<td><input type="text" name="product_name[]" class="form-control"></td>'+
                '<td><input type="text" name="quantity[]" class="form-control"></td>'+
                '<td><input type="text" name="price[]" class="form-control"></td>'+
                '<td><a href="#" class="remove">Remove</a></td>'+
            '</tr>';
    $('.detail').append(tr);
});

$('body').delegate('.remove','click',function(){
    var tr = $(this).parent().parent();
    var c = confirm("Do you want to remove this ?");
    if(c)
    {
        tr.remove();
    }
   });
 });
  </script>

在运行jquery函数之前忘了包含jquery库。