[英]Get total from table input as grand total in jquery
I have a table that makes automatically 2 calculations: 我有一个表自动进行2次计算:
How can i calculate the grand total of numbers of days and the grand total of the total to display the results in a row below the table ? 如何计算总天数和总计的总数,以便在表格下方连续显示结果 ? And i want to grasp the input values in post so that i store them in table using php.
我想掌握post中的输入值,以便我使用php将它们存储在表中。
1- table 1-表
<table class='table'>
<tr>
<th class='th'>Nbr/horses</th>
<th class='th'>dateStart</th>
<th class='th'>dateEnd</th>
<th class='th'>Nbr/days</th>
<th class='th'>Price</th>
<th class='th'>Total</th>
</tr>
<tr>
<td class='td'><input type='number' min='1' name='horse' class='horse'/></td>
<td class='td'><input type='date' name='dateStart' class='datepicker dateStart'/></td>
<td class='td'><input type='date' name='dateEnd' class='datepicker dateEnd'/></td>
<td class='td days'><input type='text' name='days'/>0</td>
<td class='td'><input type='number' min='1' name='price' class='price'/></td>
<td class='td total'> <input type='text' name='total1'/></td>
<td class='td'><button type='button' class='button'>+</button></td>
</tr>
2- functions 2-功能
let update = function(lineNode){
let dateStart = $(lineNode).find('.dateStart').datepicker('getDate');
let dateEnd = $(lineNode).find('.dateEnd').datepicker('getDate');
let days = Math.floor( (dateEnd - dateStart) / (3600*24*1000) );
days = days >= 0 ? days : 0;
$( lineNode ).find('.days').text( days );
let horse = parseInt( $(lineNode).find('.horse').val() );
let price = parseInt( $(lineNode).find('.price').val() );
let total = horse * days * price;
$( lineNode ).find('.total').text( total+' €' );
}
// add line after click
let addRow = function(lineNode){
let clone = lineNode.cloneNode(true);
$(clone).insertAfter(lineNode);
reloadEffects();
}
let reloadEffects = function(){
$('.hasDatepicker').removeClass('hasDatepicker').attr('id', '');
$('.datepicker').datepicker();
$('.horse, .price, .datepicker').change( e => {
update(e.target.parentNode.parentNode);
});
$('.button').click( e => {
addRow(e.target.parentNode.parentNode);
});
}; };
// Start
reloadEffects();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.