所以我有问题是我的输入值只有在我点击输入字段(“总计”输入字段,在“Suma”(“Kiekis”*“Kaina”=“Suma”)列下面并且只读)时才更新,但我想自动更新“总计”字段(位于“Bendra suma”附近的底部)。
JS代码:
<script>
您可以在JSFiddle中测试它的工作原理:
https://jsfiddle.net/xqy6qafk/
提前感谢您的帮助!
答案 0 :(得分:1)
删除更改,以便在keyup上激活
$(document).on('keyup', '.quantity, .price', function() {
答案 1 :(得分:1)
这会更新总数。
$(document).on('keyup change', '.quantity, .price', function() {
var row = $(this).closest('tr').get(0);
var rowPrice = $(row).find('.price').val();
var rowQuantity = $(row).find('.quantity').val();
$(row).find('.total').val((rowPrice * rowQuantity).toFixed(2));
// Get all the totals from each row and convert them to
// an array of floats. Then sum them together with reduce
var totalPrice = $('.total').map(function (index, el) {
return parseFloat($(el).val()) || 0;
}).get().reduce(function (a,b) { return a + b }, 0)
// Update the total field with the calculated totals
$('#totals').val(totalPrice)
});
答案 2 :(得分:0)
您不需要将代码放入模糊事件处理程序...
将它放在keyup / change事件处理程序部分......
删除第8行
});
和倒数第二行......
$(document).on('keyup change', '.quantity, .price', function() {
var row = $(this).closest('tr').get(0);
var rowPrice = $(row).find('.price').val();
var rowQuantity = $(row).find('.quantity').val();
$(row).find('.total').val((rowPrice * rowQuantity).toFixed(2));
var sum = 0;
$('.total').each(function() {
sum += parseFloat($(this).val()) || 0; // If a string is entered, use 0 instead.
});
$('#totals').val((sum).toFixed(2));
});
所以你有一些看起来像这样的东西......
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
void main() {
struct stat file_st;
int size=0, ret=0;
char* buf=NULL;
FILE* file = fopen("newfile", "r");
if (file==NULL) {
printf("error");
exit(1);
}
if (stat("newfile", &file_st)!=0) {
printf("stat failed\n");
exit(1);
}
buf = (char*)malloc(sizeof(file_st.st_size+1));
buf[file_st.st_size]='\0';
ret = fread(buf, 1, file_st.st_size, file);
printf("fread return value is: %d\n");
ret = fclose(file);
printf("fclose return value: %d\n", ret);
printf("%s\n", buf);
}