【问题标题】:Add row to table and calculate rows value向表中添加行并计算行值
【发布时间】:2017-11-27 11:19:49
【问题描述】:
<div class="col-xs-12 col-md-10" style="padding:0px 100px 0px 50px; color:blue;">   
        <form action="#" style="color:blue;" method="POST" >

            <div class="well well-sm" >
                <table border="collapse; border-spacing:5px;" style="background-color:pink;">
                <thead> 
                    <th>Stock ID</th>
                    <th>Medicine Name</th>
                    <th>Quantity Unit</th>
                    <th>Unit Price</th>
                    <th>Selling Price</th>
                    <th>Sold Quantity</th>
                    <th>Total Price</th>
                    <th><input type="button" value="+" id="add" class="btn btn-primary"></th>                   
                </thead>
                <tbody class="detail">
                <tr>
                    <td><input type="text" class="form-control" id="si" name="si"></td>
                    <td><input type="text" class="form-control" id="mn" name="mn" value="<?php 
                        include_once('classes/class.select.php');
                        $bill = new select();
                        $value = $bill ->billing($_POST['si']);
                            foreach($value as $row){

                            echo    $row["medi_name"];
                            }

                            ?>"></td>
                    <td><input type="text" class="form-control" id="qu" name="qu" value="<?php echo $row["quantity_unit"];?>"></td>
                    <td>
                    <input type="text" class="form-control" id="up" name="up" value="<?php echo $row["unit_price"]; ?>"></td>
                    <td>
                    <input type="text" class="form-control" id="sp" name="sp" value="<?php echo $row["selling_price"];?>"></td>
                    <td><input type="text" class="form-control" id="t" name="t" ></td>  
                    <td><input type="text" class="form-control" id="ls" name="ls" ></td>
                    <td><input type="submit" class="btn btn-success" value="Bill" name="savesel"><br></td>          
                </tr>
                </tbody> 
                </table>
            </div>



        </form> 

    </div>  

这是我的药品计费系统表。当我们给出 stock Id 时,其他列会根据相关的 stock Id 自动填充。我想像这样在该表中添加更多行。但是当我点击第二行的账单按钮时,整行都会消失。我也想计算一下总价。

<script>
function addnew(){
    var n=($('.detail tr').length-0)+1;
    var tr =
    '<tr>' +
    '<td><input type="text" class="form-control" id="si" name="si"></td>'+
    '<td><input type="text" class="form-control" id="mn" name="mn" value="<?php 
                        include_once('classes/class.select.php');
                        $bill = new select();
                        $value = $bill ->billing($_POST['si']);
                            foreach($value as $row){

                            echo    $row["medi_name"];
                            }

                            ?>"></td>'+
    '<td><input type="text" class="form-control" id="qu" name="qu" value=["quantity_unit"]></td>'+
    '<td><input type="text" class="form-control" id="up" name="up" value=["unit_price"]></td>'+
    '<td><input type="text" class="form-control" id="sp" name="sp" value=["selling_price"]></td>'+
    '<td><input type="text" class="form-control" id="t" name="t" ></td>'+   
    '<td><input type="text" class="form-control" id="ls" name="ls" ></td>'+
    '<td><input type="submit" class="btn btn-success" value="Bill" name="savesel"><br></td>'+                       
    '</tr>';
    $('.detail').append(tr);
}

$(function(){
    $('#add').click(function(){
        addnew();
    });
});
</script>

【问题讨论】:

  • 所以你的other question 仍然没有被标记为已解决,但你需要更多帮助并且仍然有代码图像;你还在等什么?

标签: php


【解决方案1】:
$("#cloneTable tfoot #addNew").on("click", function() {
    var clonedRow = $('#cloneTable tbody tr:first').clone();
    clonedRow.find('input').val('');
     $('#cloneTable tbody').append(clonedRow) ;
});

【讨论】:

  • 你可以克隆你的表 tr
  • 非常感谢您的评论
猜你喜欢
  • 2023-01-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多