2016-08-24 3 views
2

Я использую базу кода, но похоже, что скрипт не работает. Ничего не происходит, когда я нажимаю кнопку +. Я нашел этот скрипт на веб-сайте. я надеюсь, что кто-то может помочь мне с этим: 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

во-первых, ваша форма не определена должным образом,

, это должно быть как –

ответ

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

Спасибо, я должен был видеть, что сам LOL. – dennis