$.getJSON('select.php', {monthyear: $(this).val()}, function(data){
var invoicerow = '';
for (var x = 0; x < data.length; x++) {
if (data[x]['datepaid'] == '0000-00-00'){datepaid = '<span style="color:red;">Not Paid</span>'}else{datepaid = data[x]['datepaid']};
invoicerow += '<tr><td>' + data[x]['invoiceID'] + '</td><td>' + data[x]['customerID'] + '</td><td>' + data[x]['date'] + '</td><td>£' + '<span class="grandtotal">' + data[x]['grandtotal'] + '</span>' + '</td><td>' + '<a target="_NEW" href="../salesmanager/viewinvoice.php?&salesID=' + data[x]['salesID'] + '">View Invoice</a></td><td>' + datepaid + '</td></tr>';
}
$('#summarycontent').html(invoicerow);
$("select").select2();
编辑&gt;&gt;&gt;&gt;&gt;
好吧所以我到目前为止,这是有效的,但问题是它在前一个月倍增.....所以当页面加载选择框时它会显示Total:,当它第一次按下并说选择Januaury它说0英镑,然后选择feb,你得到1860英镑,但事情是Januarys总数而不是2月份,febs总计是0英镑,所以它好像结果一直落后于后面。
<script>
$(document).ready(function(){
$('#selectmonth').on('change', function (){
var sum = 0;
$('.grandtotal').each(function(){
sum += parseFloat($(this).text());
});
$('#total_price').text('£' + sum);
});
});
</script>
答案 0 :(得分:0)
好的,这似乎有效:
<script>
$(document).ready(function(){
$('#invoices').bind('DOMNodeInserted DOMNodeRemoved', function() {
var sum = 0;
$('.grandtotal').each(function(){
var tal = $(this).text();
if(isNaN(tal)) {
sum += 0;
}else{
sum += parseFloat($(this).text());};
});
$('#total_price').text('£' + sum);
});
});
</script>