2016-08-24 85 views
2

我使用codeigniting基础,但它似乎像脚本不工作。 当点击+按钮时没有任何事情发生。我在网站上找到了这个脚本。我希望有人能帮助我与它:d,衷心感谢很多丹尼斯Codeigniter Addrow不工作

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

+0

首先你的表单没有被正确定义,

”method =“post”>,它应该像“method =”post“> –

回答

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库。

+0

谢谢,我应该看到我自己大声笑。 – dennis