簡體   English   中英

如何將動態添加的行內容輸入數據庫

[英]How to enter the dynamically added row contents to a database

  <script> var i=0; currentRow = null; $("button#savebutton").click(function(){ var cat = $("#cat-list").val(); var display = $("#displayname").val(); var subcat = $("#subcat-list").val(); var order = $("#privilage").val(); i++; var new_row = "<tr id='row"+i+"' class='info'><td class='cat'>" + cat + "</td><td class='display'>" + display + "</td><td class='type'>" + subcat +"</td><td>"+order +"</td><td><span class='editrow'><a class='fa fa-edit' href='javascript: void(0);'>Edit</a></span></td><td><span class='deleterow'><a class='glyphicon glyphicon-trash' href=''>Delete</a></span></tr>"; if(currentRow){ $("table tbody").find($(currentRow)).replaceWith(new_row); currentRow = null; } else{ $("table tbody").append(new_row); } }); $(document).on('click', 'span.deleterow', function () { $(this).parents('tr').remove(); return false; }); $(document).on('click', 'span.editrow', function () { currentRow= $(this).parents('tr'); // $("#minAmt").val($(this).closest('tr').find('td.minAmt').text()); //$("#maxAmt").val($(this).closest('tr').find('td.maxAmt').text()); // $("#type").val($(this).closest('tr').find('td.type').text()); }); </script> 
 <html> <head> </head> <body> <form method="POST" action=""/> <label>Category</label> <input type="text" id="cat-list"/></br> <label>Display</label> <input type="text" id="displayname"/></br> <label>SubCategory</label> <input type="text" id="subcat-list"/></br> <label>Privilage</label> <input type="text" id="privilage"/></br> </form> <div class="col-md-12"> <div class="form-actions btnzone"> <button type="button" class="btn btn-success savebtn" style="padding: 6px 12px;margin-left: 40%;" id="savebutton" ><i class="icon-check-sign" aria-hidden="false"></i>Add</button> </div> </div> </form> <form class="form-horizontal" role="form" id="chargestableForm"> <div class="col-md-12"> <table id="pTable" class="table table-hover" width="100%" cellspacing="0" style="border: 1px; height:10px;" > <thead style="background-color:#CCE5FF"> <tr> <th>Category</th> <th>DisplayName</th> <th>Subcategory</th> <th>Order</th> <th colspan=2>Action</th> </tr> </thead> <tbody> </tbody> </table> </form> </body> </html> 
上下文:該代碼是將動態添加的行內容輸入到數據庫中。單擊添加按鈕時,輸入詳細信息將顯示為一行,再次單擊添加按鈕將添加下一行,並且該行內容是可編輯的。內容在行本身內進行更新。因此,我想將行內容輸入數據庫。

創建一個新的.php文件,它將查詢數據庫。 您現在所要做的是在所有客戶端上進行操作,您可以在jquery中使用ajax到該新創建的file.php並通過ajax發送數據,因此您不必重新加載頁面,並且數據將在click上發送

 <script> var i = 0; currentRow = null; $("button#savebutton").click(function() { var cat = $("#cat-list").val(); var display = $("#displayname").val(); var subcat = $("#subcat-list").val(); var order = $("#privilage").val(); i++; //Inserting first row to the table with edit and delete button var new_row = "<tr id='row" + i + "' class='info'><td class='cat'>" + cat + "</td><td class='display'>" + display + "</td><td class='type'>" + subcat + "</td><td>" + order + "</td><td><span class='editrow'><a class='fa fa-edit' href='javascript: void(0);'>Edit</a></span></td><td><span class='deleterow'><a class='glyphicon glyphicon-trash' href=''>Delete</a></span></tr>"; //Appending the new row to the table if (currentRow) { $("table tbody").find($(currentRow)).replaceWith(new_row); currentRow = null; } else { $("table tbody").append(new_row); } }); </script> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM